Adding utf-8 aware version of most functions to BString. They are named after
the corresponding normal functions but have a "Chars" in the name like "MoveCharsInto" or "AppendChars". Also added CountBytes() and CharAt(). This should make everyday string handling with multibyte strings a bit easier. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35371 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2009, Haiku Inc. All Rights Reserved.
|
||||
* Copyright 2001-2010, Haiku Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef __BSTRING__
|
||||
@@ -26,6 +26,8 @@ public:
|
||||
const char* String() const;
|
||||
int32 Length() const;
|
||||
int32 CountChars() const;
|
||||
int32 CountBytes(int32 fromCharOffset,
|
||||
int32 charCount) const;
|
||||
|
||||
// Assignment
|
||||
BString& operator=(const BString& string);
|
||||
@@ -43,12 +45,21 @@ public:
|
||||
|
||||
BString& SetTo(char c, int32 count);
|
||||
|
||||
BString& SetToChars(const char* string, int32 charCount);
|
||||
BString& SetToChars(const BString& string, int32 charCount);
|
||||
BString& AdoptChars(BString& from, int32 charCount);
|
||||
|
||||
// Substring copying
|
||||
BString& CopyInto(BString& into, int32 fromOffset,
|
||||
int32 length) const;
|
||||
void CopyInto(char* into, int32 fromOffset,
|
||||
int32 length) const;
|
||||
|
||||
BString& CopyCharsInto(BString& into, int32 fromCharOffset,
|
||||
int32 charCount) const;
|
||||
bool CopyCharsInto(char* into, int32* intoLength,
|
||||
int32 fromCharOffset, int32 charCount) const;
|
||||
|
||||
// Appending
|
||||
BString& operator+=(const BString& string);
|
||||
BString& operator+=(const char* string);
|
||||
@@ -61,6 +72,9 @@ public:
|
||||
BString& Append(const char* string, int32 length);
|
||||
BString& Append(char c, int32 count);
|
||||
|
||||
BString& AppendChars(const BString& string, int32 charCount);
|
||||
BString& AppendChars(const char* string, int32 charCount);
|
||||
|
||||
// Prepending
|
||||
BString& Prepend(const char* string);
|
||||
BString& Prepend(const BString& string);
|
||||
@@ -68,6 +82,10 @@ public:
|
||||
BString& Prepend(const BString& string, int32 length);
|
||||
BString& Prepend(char c, int32 count);
|
||||
|
||||
BString& PrependChars(const char* string, int32 charCount);
|
||||
BString& PrependChars(const BString& string,
|
||||
int32 charCount);
|
||||
|
||||
// Inserting
|
||||
BString& Insert(const char* string, int32 position);
|
||||
BString& Insert(const char* string, int32 length,
|
||||
@@ -81,9 +99,26 @@ public:
|
||||
int32 length, int32 position);
|
||||
BString& Insert(char c, int32 count, int32 position);
|
||||
|
||||
BString& InsertChars(const char* string, int32 charPosition);
|
||||
BString& InsertChars(const char* string, int32 charCount,
|
||||
int32 charPosition);
|
||||
BString& InsertChars(const char* string,
|
||||
int32 fromCharOffset, int32 charCount,
|
||||
int32 charPosition);
|
||||
BString& InsertChars(const BString& string,
|
||||
int32 charPosition);
|
||||
BString& InsertChars(const BString& string, int32 charCount,
|
||||
int32 charPosition);
|
||||
BString& InsertChars(const BString& string,
|
||||
int32 fromCharOffset, int32 charCount,
|
||||
int32 charPosition);
|
||||
|
||||
// Removing
|
||||
BString& Truncate(int32 newLength, bool lazy = true);
|
||||
BString& TruncateChars(int32 newCharCount, bool lazy = true);
|
||||
|
||||
BString& Remove(int32 from, int32 length);
|
||||
BString& RemoveChars(int32 fromCharOffset, int32 charCount);
|
||||
|
||||
BString& RemoveFirst(const BString& string);
|
||||
BString& RemoveLast(const BString& string);
|
||||
@@ -93,11 +128,17 @@ public:
|
||||
BString& RemoveLast(const char* string);
|
||||
BString& RemoveAll(const char* string);
|
||||
|
||||
BString& RemoveSet(const char* setOfCharsToRemove);
|
||||
BString& RemoveSet(const char* setOfBytesToRemove);
|
||||
BString& RemoveCharsSet(const char* setOfCharsToRemove);
|
||||
|
||||
BString& MoveInto(BString& into, int32 from, int32 length);
|
||||
void MoveInto(char* into, int32 from, int32 length);
|
||||
|
||||
BString& MoveCharsInto(BString& into, int32 fromCharOffset,
|
||||
int32 charCount);
|
||||
bool MoveCharsInto(char* into, int32* intoLength,
|
||||
int32 fromCharOffset, int32 charCount);
|
||||
|
||||
// Compare functions
|
||||
bool operator<(const BString& string) const;
|
||||
bool operator<=(const BString& string) const;
|
||||
@@ -120,6 +161,12 @@ public:
|
||||
int Compare(const char* string) const;
|
||||
int Compare(const BString& string, int32 length) const;
|
||||
int Compare(const char* string, int32 length) const;
|
||||
|
||||
int CompareChars(const BString& string,
|
||||
int32 charCount) const;
|
||||
int CompareChars(const char* string,
|
||||
int32 charCount) const;
|
||||
|
||||
int ICompare(const BString& string) const;
|
||||
int ICompare(const char* string) const;
|
||||
int ICompare(const BString& string, int32 length) const;
|
||||
@@ -135,6 +182,11 @@ public:
|
||||
int32 FindFirst(char c) const;
|
||||
int32 FindFirst(char c, int32 fromOffset) const;
|
||||
|
||||
int32 FindFirstChars(const BString& string,
|
||||
int32 fromCharOffset) const;
|
||||
int32 FindFirstChars(const char* string,
|
||||
int32 fromCharOffset) const;
|
||||
|
||||
int32 FindLast(const BString& string) const;
|
||||
int32 FindLast(const char* string) const;
|
||||
int32 FindLast(const BString& string,
|
||||
@@ -144,6 +196,11 @@ public:
|
||||
int32 FindLast(char c) const;
|
||||
int32 FindLast(char c, int32 beforeOffset) const;
|
||||
|
||||
int32 FindLastChars(const BString& string,
|
||||
int32 beforeCharOffset) const;
|
||||
int32 FindLastChars(const char* string,
|
||||
int32 beforeCharOffset) const;
|
||||
|
||||
int32 IFindFirst(const BString& string) const;
|
||||
int32 IFindFirst(const char* string) const;
|
||||
int32 IFindFirst(const BString& string,
|
||||
@@ -175,6 +232,12 @@ public:
|
||||
const char* withThis, int32 maxReplaceCount,
|
||||
int32 fromOffset = 0);
|
||||
|
||||
BString& ReplaceAllChars(const char* replaceThis,
|
||||
const char* withThis, int32 fromCharOffset);
|
||||
BString& ReplaceChars(const char* replaceThis,
|
||||
const char* withThis, int32 maxReplaceCount,
|
||||
int32 fromCharOffset);
|
||||
|
||||
BString& IReplaceFirst(char replaceThis, char withThis);
|
||||
BString& IReplaceLast(char replaceThis, char withThis);
|
||||
BString& IReplaceAll(char replaceThis, char withThis,
|
||||
@@ -191,8 +254,12 @@ public:
|
||||
const char* withThis, int32 maxReplaceCount,
|
||||
int32 fromOffset = 0);
|
||||
|
||||
BString& ReplaceSet(const char* setOfChars, char with);
|
||||
BString& ReplaceSet(const char* setOfChars, const char* with);
|
||||
BString& ReplaceSet(const char* setOfBytes, char with);
|
||||
BString& ReplaceSet(const char* setOfBytes,
|
||||
const char* with);
|
||||
|
||||
BString& ReplaceCharsSet(const char* setOfChars,
|
||||
const char* with);
|
||||
|
||||
// Unchecked char access
|
||||
char operator[](int32 index) const;
|
||||
@@ -205,6 +272,9 @@ public:
|
||||
|
||||
// Checked char access
|
||||
char ByteAt(int32 index) const;
|
||||
const char* CharAt(int32 charIndex, int32* bytes = NULL) const;
|
||||
bool CharAt(int32 charIndex, char* buffer,
|
||||
int32* bytes) const;
|
||||
|
||||
// Fast low-level manipulation
|
||||
char* LockBuffer(int32 maxLength);
|
||||
|
||||
Reference in New Issue
Block a user