Browse Source

tags/2021-05-28
jules 17 years ago
parent
commit
473753e9aa
3 changed files with 16 additions and 7 deletions
  1. +5
    -0
      src/juce_core/text/juce_CharacterFunctions.cpp
  2. +3
    -2
      src/juce_core/text/juce_CharacterFunctions.h
  3. +8
    -5
      src/juce_core/text/juce_String.cpp

+ 5
- 0
src/juce_core/text/juce_CharacterFunctions.cpp View File

@@ -94,6 +94,11 @@ void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxC
wcstombs (dest, src, maxChars);
}
int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
{
return (int) wcstombs (0, src, 0);
}
void CharacterFunctions::append (char* dest, const char* src) throw()
{
strcat (dest, src);


+ 3
- 2
src/juce_core/text/juce_CharacterFunctions.h View File

@@ -91,11 +91,12 @@ public:
static int length (const char* const s) throw();
static int length (const juce_wchar* const s) throw();
static void copy (char* dest, const char* src, const int maxChars) throw();
static void copy (char* dest, const char* src, const int maxBytes) throw();
static void copy (juce_wchar* dest, const juce_wchar* src, const int maxChars) throw();
static void copy (juce_wchar* dest, const char* src, const int maxChars) throw();
static void copy (char* dest, const juce_wchar* src, const int maxChars) throw();
static void copy (char* dest, const juce_wchar* src, const int maxBytes) throw();
static int bytesRequiredForCopy (const juce_wchar* src) throw();
static void append (char* dest, const char* src) throw();
static void append (juce_wchar* dest, const juce_wchar* src) throw();


+ 8
- 5
src/juce_core/text/juce_String.cpp View File

@@ -202,12 +202,15 @@ String::String (const juce_wchar* const t) throw()
{
if (t != 0 && *t != 0)
{
#if JUCE_STRINGS_ARE_UNICODE
const int len = CharacterFunctions::length (t);
createInternal (len);
#if JUCE_STRINGS_ARE_UNICODE
memcpy (text->text, t, (len + 1) * sizeof (tchar));
#else
const int len = CharacterFunctions::bytesRequiredForCopy (t);
createInternal (len);
CharacterFunctions::copy (text->text, t, len + 1);
#endif
}
@@ -492,7 +495,7 @@ String::operator const char*() const throw()
String* const mutableThis = const_cast <String*> (this);
mutableThis->dupeInternalIfMultiplyReferenced();
int len = CharacterFunctions::length (text->text) + 1;
int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1;
mutableThis->text = (InternalRefCountedStringHolder*)
juce_realloc (text, sizeof (InternalRefCountedStringHolder)
+ (len * sizeof (juce_wchar) + len));
@@ -535,13 +538,13 @@ String::operator const juce_wchar*() const throw()
#endif
void String::copyToBuffer (char* const destBuffer,
const int maxCharsToCopy) const throw()
const int bufferSizeBytes) const throw()
{
const int len = jmin (maxCharsToCopy, length());
#if JUCE_STRINGS_ARE_UNICODE
const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text));
CharacterFunctions::copy (destBuffer, text->text, len);
#else
const int len = jmin (bufferSizeBytes, length());
memcpy (destBuffer, text->text, len * sizeof (tchar));
#endif


Loading…
Cancel
Save