BString: rename SetCharAt to SetByteAt

Makes it clear that it operates on bytes, not unicode codepoints.
Thanks to mmlr for remembering me of this subtlety.
This commit is contained in:
Adrien Destugues
2017-01-12 22:03:51 +01:00
parent 0c5219a1d6
commit bdd02e0d9d
7 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -309,7 +309,7 @@ public:
// Fast low-level manipulation // Fast low-level manipulation
char* LockBuffer(int32 maxLength); char* LockBuffer(int32 maxLength);
BString& UnlockBuffer(int32 length = -1); BString& UnlockBuffer(int32 length = -1);
BString& SetCharAt(int32 pos, char to); BString& SetByteAt(int32 pos, char to);
// Upercase <-> Lowercase // Upercase <-> Lowercase
BString& ToLower(); BString& ToLower();
+4 -4
View File
@@ -288,13 +288,13 @@ ExpressionTextView::SetValue(BString value)
if (digit != 10) if (digit != 10)
break; break;
value.SetCharAt(offset, '0'); value.SetByteAt(offset, '0');
} }
if (digit == 10) { if (digit == 10) {
// carry over, shift the result // carry over, shift the result
if (value[firstDigit + 1] == '.') { if (value[firstDigit + 1] == '.') {
value.SetCharAt(firstDigit + 1, '0'); value.SetByteAt(firstDigit + 1, '0');
value.SetCharAt(firstDigit, '.'); value.SetByteAt(firstDigit, '.');
} }
value.Insert('1', 1, firstDigit); value.Insert('1', 1, firstDigit);
@@ -311,7 +311,7 @@ ExpressionTextView::SetValue(BString value)
value << 'E' << exponent; value << 'E' << exponent;
} else { } else {
// increase the current digit value with one // increase the current digit value with one
value.SetCharAt(offset, char(digit + 48)); value.SetByteAt(offset, char(digit + 48));
// set offset to last digit // set offset to last digit
offset = value.FindFirst('E'); offset = value.FindFirst('E');
+1 -1
View File
@@ -2435,7 +2435,7 @@ BrowserWindow::_EncodeURIComponent(const BString& search)
for (int32 i = 0; i < result.Length(); i++) { for (int32 i = 0; i < result.Length(); i++) {
if (escCharList.FindFirst(result[i]) != B_ERROR) { if (escCharList.FindFirst(result[i]) != B_ERROR) {
sprintf(hexcode, "%02X", (unsigned int)result[i]); sprintf(hexcode, "%02X", (unsigned int)result[i]);
result.SetCharAt(i, '%'); result.SetByteAt(i, '%');
result.Insert(hexcode, i + 1); result.Insert(hexcode, i + 1);
i += 2; i += 2;
} }
+1 -1
View File
@@ -247,7 +247,7 @@ HaikuMailFormatFilter::_RemoveExtraWhitespace(BString& name)
if (i == remove + 1 || i == name.Length()) if (i == remove + 1 || i == name.Length())
remove++; remove++;
else else
name.SetCharAt(i - spaces, ' '); name.SetByteAt(i - spaces, ' ');
name.Remove(i - remove, remove); name.Remove(i - remove, remove);
i -= remove; i -= remove;
spaces = 0; spaces = 0;
+1 -1
View File
@@ -1904,7 +1904,7 @@ BString::UnlockBuffer(int32 length)
BString& BString&
BString::SetCharAt(int32 pos, char to) BString::SetByteAt(int32 pos, char to)
{ {
if (pos < Length() && _MakeWritable() == B_OK) if (pos < Length() && _MakeWritable() == B_OK)
fPrivateData[pos] = to; fPrivateData[pos] = to;
+3 -3
View File
@@ -229,14 +229,14 @@ DNSTools::ConvertToDNSName(const BString& string)
// set a counts to the dot // set a counts to the dot
diff = dot - 1 - lastDot; diff = dot - 1 - lastDot;
outString.SetCharAt(lastDot, (char)diff); outString.SetByteAt(lastDot, (char)diff);
lastDot = dot; lastDot = dot;
} }
} else } else
lastDot = 0; lastDot = 0;
diff = outString.CountChars() - 1 - lastDot; diff = outString.CountChars() - 1 - lastDot;
outString.SetCharAt(lastDot, (char)diff); outString.SetByteAt(lastDot, (char)diff);
return outString; return outString;
} }
@@ -259,7 +259,7 @@ DNSTools::ConvertFromDNSName(const BString& string)
if (dot == 0) if (dot == 0)
break; break;
// set a "." // set a "."
outString.SetCharAt(nextDot, '.'); outString.SetByteAt(nextDot, '.');
nextDot+= dot + 1; nextDot+= dot + 1;
} }
return outString; return outString;
@@ -27,7 +27,7 @@ StringCharAccessTest::PerformTest(void)
//&operator[] //&operator[]
NextSubTest(); NextSubTest();
string.SetCharAt(0, 'a'); string.SetByteAt(0, 'a');
CPPUNIT_ASSERT(strcmp(string.String(), "a simple string") == 0); CPPUNIT_ASSERT(strcmp(string.String(), "a simple string") == 0);
//ByteAt(int32) //ByteAt(int32)