Skip to content
This repository has been archived by the owner on Jun 17, 2019. It is now read-only.

Commit

Permalink
String::toLower() and toUpper() need to do a copy-on-write
Browse files Browse the repository at this point in the history
to keep String immutable!
  • Loading branch information
lww committed Feb 8, 2010
1 parent 470df68 commit 1624e89
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/zmm/strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,26 @@ String String::toLower()
if (!base)
return nil;

for (int i = 0; i < base->len; i++)
String result = String(base->data, base->len);
for (int i = 0; i < result.base->len; i++)
{
base->data[i] = tolower(base->data[i]);
result.base->data[i] = tolower(result.base->data[i]);
}

return String(base);
return result;
}

String String::toUpper()
{
if (!base)
return nil;

String result = String(base->data, base->len);
for (int i = 0; i < base->len; i++)
{
base->data[i] = toupper(base->data[i]);
result.base->data[i] = toupper(result.base->data[i]);
}

return String(base);
return result;
}

long String::toLong()
Expand Down

0 comments on commit 1624e89

Please sign in to comment.