1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-07 04:10:08 +00:00
This commit is contained in:
jules 2008-06-05 20:50:23 +00:00
parent e9691fb437
commit 473753e9aa
3 changed files with 16 additions and 7 deletions

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);

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();

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