bool nsAString::SetLength(uint32_t aLen) { char_type *data; NS_StringGetMutableData(*this, aLen, &data); return data != nullptr; }
nsAString::char_type* nsAString::BeginWriting(uint32_t aLen) { char_type *data; NS_StringGetMutableData(*this, aLen, &data); return data; }
nsAString::char_type* nsAString::EndWriting() { char_type *data; uint32_t len = NS_StringGetMutableData(*this, PR_UINT32_MAX, &data); return data + len; }
PRBool nsAString::SetLength(PRUint32 aLen) { char_type *data; NS_StringGetMutableData(*this, aLen, &data); return data != nsnull; }
uint32_t nsAString::BeginWriting(char_type **begin, char_type **end, uint32_t newSize) { uint32_t len = NS_StringGetMutableData(*this, newSize, begin); if (end) *end = *begin + len; return len; }
uint32_t nsAString::BeginWriting(char_type** aBegin, char_type** aEnd, uint32_t aNewSize) { uint32_t len = NS_StringGetMutableData(*this, aNewSize, aBegin); if (aEnd) { *aEnd = *aBegin + len; } return len; }
void ToUpperCase(const nsAString& aSource, nsAString& aDest) { const char16_t *in; char16_t *out; uint32_t len = NS_StringGetData(aSource, &in); NS_StringGetMutableData(aDest, len, &out); NS_ASSERTION(out, "Uh..."); ToUpperCase(in, out, len); }
void ToUpperCase(const nsAString& aSource, nsAString& aDest) { const PRUnichar *in; PRUnichar *out; PRUint32 len = NS_StringGetData(aSource, &in); NS_StringGetMutableData(aDest, len, &out); NS_ASSERTION(out, "Uh..."); ToUpperCase(in, out, len); }
void CompressWhitespace(nsAString& aString) { char16_t* start; uint32_t len = NS_StringGetMutableData(aString, UINT32_MAX, &start); char16_t* end = start + len; char16_t* from = start; char16_t* to = start; // Skip any leading whitespace while (from < end && NS_IsAsciiWhitespace(*from)) { from++; } while (from < end) { char16_t theChar = *from++; if (NS_IsAsciiWhitespace(theChar)) { // We found a whitespace char, so skip over any more while (from < end && NS_IsAsciiWhitespace(*from)) { from++; } // Turn all whitespace into spaces theChar = ' '; } *to++ = theChar; } // Drop any trailing space if (to > start && to[-1] == ' ') { to--; } // Re-terminate the string *to = '\0'; // Set the new length aString.SetLength(to - start); }
void CompressWhitespace(nsAString& aString) { aString.Trim(" \n\t\r"); PRUnichar *start; PRUint32 len = NS_StringGetMutableData(aString, PR_UINT32_MAX, &start); PRUnichar *end = start + len; for (PRUnichar *cur = start; cur < end; ++cur) { if (!NS_IsAsciiWhitespace(*cur)) continue; *cur = ' '; PRUnichar *wend; for (wend = cur + 1; wend < end && NS_IsAsciiWhitespace(*wend); ++wend) { // nothing to do but loop } if (wend == cur + 1) continue; PRUint32 wlen = wend - cur - 1; // fix "end" end -= wlen; // move everything forwards a bit for (PRUnichar *m = cur + 1; m < end; ++m) { *m = *(m + wlen); } } // re-terminate *end = '\0'; // Set the new length. aString.SetLength(end - start); }