JX Application Framework
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Friends | List of all members
JString Class Reference

#include <JString.h>

Public Types

enum  ExponentDisplay {
  kStandardExponent = -10000 ,
  kForceExponent = -9999 ,
  kForceNoExponent = 0 ,
  kUseGivenExponent = 1
}
 
enum  Base {
  kBase10 = 10 ,
  kBase2 = 2 ,
  kBase8 = 8 ,
  kBase16 = 16
}
 
enum  Case {
  kIgnoreCase = 0 ,
  kCompareCase = 1
}
 
enum  Copy {
  kNoCopy = 0 ,
  kCopy = 1
}
 

Public Member Functions

 JString ()
 
 JString (const JString &str, const Copy copy=kCopy)
 
 JString (const JString &str, const JCharacterRange &range, const Copy copy=kCopy)
 
 JString (const JUtf8Byte *str, const JSize byteCount, const Copy copy=kCopy)
 
 JString (const JUtf8Byte *str, const JUtf8ByteRange &range, const Copy copy=kCopy)
 
 JString (const JUtf8Character &c)
 
 JString (const std::string &str, const JUtf8ByteRange &range)
 
 JString (const bool normalize)
 
 JString (const JUtf8Byte *str, const Copy copy=kCopy)
 
 JString (const std::string &str)
 
 JString (const JUInt64 number, const Base base=kBase10, const bool pad=false)
 
 JString (const JFloat number, const JInteger precision=kPrecisionAsNeeded, const ExponentDisplay expDisplay=kStandardExponent, const JInteger exponent=0, const JInteger sigDigitCount=0)
 
 ~JString ()
 
void * operator new (size_t sz) noexcept
 
void * operator new (size_t size, const JUtf8Byte *file, const JUInt32 line, const int type, const bool assert) noexcept
 
void * operator new (size_t sz, const bool forceShallow) noexcept
 
void operator delete (void *memory) noexcept
 
JStringoperator= (const JString &str)
 
JStringoperator= (const JUtf8Byte *str)
 
JStringoperator= (const std::string &str)
 
JStringoperator= (const JUtf8Character &c)
 
JStringoperator+= (const JString &str)
 
JStringoperator+= (const JUtf8Byte *str)
 
JStringoperator+= (const std::string &str)
 
JStringoperator+= (const JUtf8Character &c)
 
void Set (const JString &str)
 
void Set (const JString &str, const JCharacterRange &range)
 
void Set (const JUtf8Byte *str)
 
void Set (const JUtf8Byte *str, const JSize byteCount)
 
void Set (const JUtf8Byte *str, const JUtf8ByteRange &range)
 
void Set (const std::string &str)
 
void Set (const std::string &str, const JUtf8ByteRange &range)
 
void Set (const JUtf8Character &c)
 
void Clear ()
 
bool IsEmpty () const
 
JSize GetCharacterCount () const
 
JSize GetByteCount () const
 
bool CharacterIndexValid (const JIndex index) const
 
bool ByteIndexValid (const JIndex index) const
 
bool RangeValid (const JCharacterRange &range) const
 
bool RangeValid (const JUtf8ByteRange &range) const
 
bool IsAscii () const
 
JUtf8Character GetFirstCharacter () const
 
JUtf8Character GetLastCharacter () const
 
const JUtf8ByteGetBytes () const
 
JUtf8ByteAllocateBytes () const
 
bool IsOwner () const
 
const JUtf8ByteGetRawBytes () const
 
bool StartsWith (const JString &str, const Case caseSensitive=kCompareCase) const
 
bool StartsWith (const JString &str, const JCharacterRange &range, const Case caseSensitive=kCompareCase) const
 
bool StartsWith (const JUtf8Byte *str, const Case caseSensitive=kCompareCase) const
 
bool StartsWith (const JUtf8Byte *str, const JSize byteCount, const Case caseSensitive=kCompareCase) const
 
bool StartsWith (const JUtf8Byte *str, const JUtf8ByteRange &range, const Case caseSensitive=kCompareCase) const
 
bool StartsWith (const JUtf8Character &c, const Case caseSensitive=kCompareCase) const
 
bool StartsWith (const std::string &str, const Case caseSensitive=kCompareCase) const
 
bool StartsWith (const std::string &str, const JUtf8ByteRange &range, const Case caseSensitive=kCompareCase) const
 
bool Contains (const JString &str, const Case caseSensitive=kCompareCase) const
 
bool Contains (const JString &str, const JCharacterRange &range, const Case caseSensitive=kCompareCase) const
 
bool Contains (const JUtf8Byte *str, const Case caseSensitive=kCompareCase) const
 
bool Contains (const JUtf8Byte *str, const JSize byteCount, const Case caseSensitive=kCompareCase) const
 
bool Contains (const JUtf8Byte *str, const JUtf8ByteRange &range, const Case caseSensitive=kCompareCase) const
 
bool Contains (const JUtf8Character &c, const Case caseSensitive=kCompareCase) const
 
bool Contains (const std::string &str, const Case caseSensitive=kCompareCase) const
 
bool Contains (const std::string &str, const JUtf8ByteRange &range, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const JString &str, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const JString &str, const JCharacterRange &range, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const JUtf8Byte *str, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const JUtf8Byte *str, const JSize byteCount, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const JUtf8Byte *str, const JUtf8ByteRange &range, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const JUtf8Character &c, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const std::string &str, const Case caseSensitive=kCompareCase) const
 
bool EndsWith (const std::string &str, const JUtf8ByteRange &range, const Case caseSensitive=kCompareCase) const
 
JString EncodeBase64 () const
 
bool DecodeBase64 (JString *str) const
 
void Read (std::istream &input, const JSize byteCount)
 
void ReadDelimited (std::istream &input)
 
void Print (std::ostream &output) const
 
void PrintHex (std::ostream &output) const
 
JSize GetMinLgSize () const
 
void SetMinLgSize (const JSize lgSize)
 
void Prepend (const JString &str)
 
void Prepend (const JUtf8Byte *str)
 
void Prepend (const JUtf8Byte *str, const JSize byteCount)
 
void Prepend (const std::string &str)
 
void Prepend (const JUtf8Character &c)
 
void Append (const JString &str)
 
void Append (const JUtf8Byte *str)
 
void Append (const JUtf8Byte *str, const JSize byteCount)
 
void Append (const std::string &str)
 
void Append (const JUtf8Character &c)
 
void TrimWhitespace ()
 
void ToLower ()
 
void ToUpper ()
 
bool MatchCase (const JString &source, const JCharacterRange &sourceRange)
 
bool MatchCase (const JUtf8Byte *source, const JUtf8ByteRange &sourceRange)
 
bool MatchCase (const std::string &source, const JUtf8ByteRange &sourceRange)
 
bool MatchCase (const JString &source, const JCharacterRange &sourceRange, const JCharacterRange &destRange)
 
bool MatchCase (const JUtf8Byte *source, const JUtf8ByteRange &sourceRange, const JCharacterRange &destRange)
 
bool MatchCase (const std::string &source, const JUtf8ByteRange &sourceRange, const JCharacterRange &destRange)
 
void Split (const JUtf8Byte *separator, JPtrArray< JString > *partList, const JSize limit=0, const bool includeSeparators=false) const
 
void Split (const JString &separator, JPtrArray< JString > *partList, const JSize limit=0, const bool includeSeparators=false) const
 
void Split (const JRegex &separator, JPtrArray< JString > *partList, const JSize limit=0, const bool includeSeparators=false) const
 
bool IsFloat () const
 
bool ConvertToFloat (JFloat *value) const
 
bool IsInteger (const JSize base=10) const
 
bool ConvertToInteger (JInteger *value, const JSize base=10) const
 
bool IsUInt (const JSize base=10) const
 
bool IsHexValue () const
 
bool ConvertToUInt (JUInt *value, const JSize base=10) const
 

Static Public Member Functions

static bool IsFloat (const JUtf8Byte *str)
 
static bool IsFloat (const JUtf8Byte *str, const JSize byteCount)
 
static bool ConvertToFloat (const JUtf8Byte *str, JFloat *value)
 
static bool ConvertToFloat (const JUtf8Byte *str, const JSize byteCount, JFloat *value)
 
static bool IsInteger (const JUtf8Byte *str, const JSize base=10)
 
static bool IsInteger (const JUtf8Byte *str, const JSize byteCount, const JSize base)
 
static bool ConvertToInteger (const JUtf8Byte *str, JInteger *value, const JSize base=10)
 
static bool ConvertToInteger (const JUtf8Byte *str, const JSize byteCount, JInteger *value, const JSize base=10)
 
static bool IsUInt (const JUtf8Byte *str, const JSize base=10)
 
static bool IsUInt (const JUtf8Byte *str, const JSize byteCount, const JSize base)
 
static bool IsHexValue (const JUtf8Byte *str)
 
static bool IsHexValue (const JUtf8Byte *str, const JSize byteCount)
 
static bool ConvertToUInt (const JUtf8Byte *str, JUInt *value, const JSize base=10)
 
static bool ConvertToUInt (const JUtf8Byte *str, const JSize byteCount, JUInt *value, const JSize base=10)
 
static bool IsEmpty (const JUtf8Byte *s)
 
static bool IsEmpty (const JString *s)
 
static bool IsValid (const JUtf8Byte *s)
 
static bool IsValid (const JUtf8Byte *s, const JUtf8ByteRange &range)
 
static JSize CountCharacters (const JUtf8Byte *str)
 
static JSize CountCharacters (const JUtf8Byte *str, const JSize byteCount)
 
static JSize CountCharacters (const JUtf8Byte *str, const JUtf8ByteRange &range)
 
static JSize CountBytes (const JUtf8Byte *str, const JSize characterCount)
 
static bool CountBytesBackward (const JUtf8Byte *str, const JSize byteOffset, const JSize characterCount, JSize *byteCount)
 
static JUtf8ByteRange CharacterToUtf8ByteRange (const JUtf8Byte *str, const JCharacterRange &range)
 
static int Compare (const JString &s1, const JString &s2, const Case caseSensitive=kCompareCase)
 
static int Compare (const JString &s1, const JUtf8Byte *s2, const Case caseSensitive=kCompareCase)
 
static int Compare (const JUtf8Byte *s1, const JString &s2, const Case caseSensitive=kCompareCase)
 
static int Compare (const JUtf8Byte *s1, const JUtf8Byte *s2, const Case caseSensitive=kCompareCase)
 
static int Compare (const JString &s1, const std::string &s2, const Case caseSensitive=kCompareCase)
 
static int Compare (const std::string &s1, const JString &s2, const Case caseSensitive=kCompareCase)
 
static int Compare (const JUtf8Byte *s1, const JSize byteCount1, const JUtf8Byte *s2, const JSize byteCount2, const Case caseSensitive=kCompareCase)
 
static int CompareMaxNBytes (const JUtf8Byte *s1, const JUtf8Byte *s2, const JSize N, const Case caseSensitive=kCompareCase)
 
static JSize CalcCharacterMatchLength (const JString &s1, const JString &s2, const Case caseSensitive=kCompareCase)
 
static JSize Normalize (const JUtf8Byte *source, const JSize byteCount, JUtf8Byte **destination)
 
static JSize CopyNormalizedBytes (const JUtf8Byte *source, const JSize maxBytes, JUtf8Byte *destination, const JSize capacity)
 

Static Public Attributes

static const JInteger kPrecisionAsNeeded = -1
 
static const JInteger kDefSigDigitCount = 16
 
static const JString empty
 
static const JString newline
 
static JSize theDefaultMinLgSize = 5
 

Protected Member Functions

const JUtf8ByteGetUnterminatedBytes () const
 
void SetIterator (JStringIterator *iter) const
 
JUtf8ByteRange CharacterToUtf8ByteRange (const JCharacterRange &range) const
 
bool SearchForward (const JUtf8Byte *str, const JSize byteCount, const Case caseSensitive, JIndex *byteIndex) const
 
bool SearchBackward (const JUtf8Byte *str, const JSize byteCount, const Case caseSensitive, JIndex *byteIndex) const
 
void ReplaceBytes (const JUtf8ByteRange &replaceRange, const JUtf8Byte *stringToInsert, const JSize insertByteCount)
 
bool MatchCase (const JUtf8Byte *source, const JUtf8ByteRange &sourceRange, const JUtf8ByteRange &destRange)
 

Friends

class JStringIterator
 
std::istream & operator>> (std::istream &, JString &)
 
std::ostream & operator<< (std::ostream &, const JString &)
 

Detailed Description

This class was not designed to be a base class!  If you need to override it,
be sure to make the destructor virtual.

Note that operator== is case sensitive, as one would expect.  To avoid the
UNIX method of sorting capitalized names separately in front of lowercase
names, operator< and operator> are not case sensitive.  One should therefore
not mix == with < and > when comparing strings.

Since stringstream doesn't provide the control we need when converting a number
to a string, we use the NumConvert and StrUtil modules.  We include them at
the end of the file so they are completely hidden and JString is self-contained.

By default, JString normalizes all text, so comparing strings is sane.
In certain cases, however, this behavior is not desirable, e.g., when
the string contains nullptr.  The default constructor accepts an optional
"normalize" flag to disable normalization.  This can only be set in the
constructor and cannot be changed afterwards.

Member Enumeration Documentation

◆ Base

Enumerator
kBase10 
kBase2 
kBase8 
kBase16 

◆ Case

Enumerator
kIgnoreCase 
kCompareCase 

◆ Copy

Enumerator
kNoCopy 
kCopy 

◆ ExponentDisplay

Enumerator
kStandardExponent 
kForceExponent 
kForceNoExponent 
kUseGivenExponent 

Constructor & Destructor Documentation

◆ JString() [1/12]

JString::JString ( )
inline

◆ JString() [2/12]

JString::JString ( const JString str,
const Copy  copy = kCopy 
)

◆ JString() [3/12]

JString::JString ( const JString str,
const JCharacterRange range,
const Copy  copy = kCopy 
)

◆ JString() [4/12]

JString::JString ( const JUtf8Byte str,
const JSize  byteCount,
const Copy  copy = kCopy 
)

◆ JString() [5/12]

JString::JString ( const JUtf8Byte str,
const JUtf8ByteRange range,
const Copy  copy = kCopy 
)

◆ JString() [6/12]

JString::JString ( const JUtf8Character c)
inline

◆ JString() [7/12]

JString::JString ( const std::string &  str,
const JUtf8ByteRange range 
)

◆ JString() [8/12]

JString::JString ( const bool  normalize)
explicit

◆ JString() [9/12]

JString::JString ( const JUtf8Byte str,
const Copy  copy = kCopy 
)
inlineexplicit

◆ JString() [10/12]

JString::JString ( const std::string &  str)
inlineexplicit

◆ JString() [11/12]

JString::JString ( const JUInt64  number,
const Base  base = kBase10,
const bool  pad = false 
)
explicit

◆ JString() [12/12]

JString::JString ( const JFloat  number,
const JInteger  precision = kPrecisionAsNeeded,
const ExponentDisplay  expDisplay = kStandardExponent,
const JInteger  exponent = 0,
const JInteger  sigDigitCount = 0 
)
explicit

◆ ~JString()

JString::~JString ( )

Member Function Documentation

◆ AllocateBytes()

JUtf8Byte * JString::AllocateBytes ( ) const

This allocates a new pointer, which the caller is responsible for deleting via "delete []".

◆ Append() [1/5]

void JString::Append ( const JString str)
inline

◆ Append() [2/5]

void JString::Append ( const JUtf8Byte str)
inline

◆ Append() [3/5]

void JString::Append ( const JUtf8Byte str,
const JSize  byteCount 
)

◆ Append() [4/5]

void JString::Append ( const JUtf8Character c)
inline

◆ Append() [5/5]

void JString::Append ( const std::string &  str)
inline

◆ ByteIndexValid()

bool JString::ByteIndexValid ( const JIndex  index) const
inline

◆ CalcCharacterMatchLength()

JSize JString::CalcCharacterMatchLength ( const JString s1,
const JString s2,
const Case  caseSensitive = kCompareCase 
)
static

Calculates the number of characters that match from the beginning of the given strings.

CalcMatchLength("abc", "abd") -> 2 CalcMatchLength("abc", "xyz") -> 0 CalcMatchLength("abc", "aBd", false) -> 2

◆ CharacterIndexValid()

bool JString::CharacterIndexValid ( const JIndex  index) const
inline

◆ CharacterToUtf8ByteRange() [1/2]

JUtf8ByteRange JString::CharacterToUtf8ByteRange ( const JCharacterRange range) const
inlineprotected

◆ CharacterToUtf8ByteRange() [2/2]

JUtf8ByteRange JString::CharacterToUtf8ByteRange ( const JUtf8Byte str,
const JCharacterRange range 
)
static

◆ Clear()

void JString::Clear ( )

◆ Compare() [1/7]

int JString::Compare ( const JString s1,
const JString s2,
const Case  caseSensitive = kCompareCase 
)
inlinestatic
Replaces strcmp(): + if s1>s2, 0 if s1==s2, - if s1<s2

◆ Compare() [2/7]

int JString::Compare ( const JString s1,
const JUtf8Byte s2,
const Case  caseSensitive = kCompareCase 
)
inlinestatic

◆ Compare() [3/7]

int JString::Compare ( const JString s1,
const std::string &  s2,
const Case  caseSensitive = kCompareCase 
)
inlinestatic

◆ Compare() [4/7]

int JString::Compare ( const JUtf8Byte s1,
const JSize  length1,
const JUtf8Byte s2,
const JSize  length2,
const Case  caseSensitive = kCompareCase 
)
static

Replaces strcmp(): + if s1>s2, 0 if s1==s2, - if s1<s2

http://demo.icu-project.org/icu-bin/collation.html

◆ Compare() [5/7]

int JString::Compare ( const JUtf8Byte s1,
const JString s2,
const Case  caseSensitive = kCompareCase 
)
inlinestatic

◆ Compare() [6/7]

int JString::Compare ( const JUtf8Byte s1,
const JUtf8Byte s2,
const Case  caseSensitive = kCompareCase 
)
inlinestatic

◆ Compare() [7/7]

int JString::Compare ( const std::string &  s1,
const JString s2,
const Case  caseSensitive = kCompareCase 
)
inlinestatic

◆ CompareMaxNBytes()

int JString::CompareMaxNBytes ( const JUtf8Byte s1,
const JUtf8Byte s2,
const JSize  N,
const Case  caseSensitive = kCompareCase 
)
static

Replaces strncmp(): + if s1>s2, 0 if s1==s2, - if s1<s2

◆ Contains() [1/8]

bool JString::Contains ( const JString str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ Contains() [2/8]

bool JString::Contains ( const JString str,
const JCharacterRange range,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ Contains() [3/8]

bool JString::Contains ( const JUtf8Byte str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ Contains() [4/8]

bool JString::Contains ( const JUtf8Byte str,
const JSize  byteCount,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ Contains() [5/8]

bool JString::Contains ( const JUtf8Byte str,
const JUtf8ByteRange range,
const Case  caseSensitive = kCompareCase 
) const

◆ Contains() [6/8]

bool JString::Contains ( const JUtf8Character c,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ Contains() [7/8]

bool JString::Contains ( const std::string &  str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ Contains() [8/8]

bool JString::Contains ( const std::string &  str,
const JUtf8ByteRange range,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ ConvertToFloat() [1/3]

bool JString::ConvertToFloat ( const JUtf8Byte str,
const JSize  byteCount,
JFloat value 
)
static

We cannot provide a public interface that takes JUtf8Byte* + byteCount because strto*() does not provide this interface. We use it internally as an optimization since JStrings know their length.

If we tried to provide the JUtf8Byte* + byteCount interface, we could not stop strto*() from gobbling digits beyond byteCount, which would obviously be an error. Convert string to a floating point value. Returns true if successful.

This function accepts hex values like 0x2A.

◆ ConvertToFloat() [2/3]

bool JString::ConvertToFloat ( const JUtf8Byte str,
JFloat value 
)
inlinestatic

◆ ConvertToFloat() [3/3]

bool JString::ConvertToFloat ( JFloat value) const
inline

◆ ConvertToInteger() [1/3]

bool JString::ConvertToInteger ( const JUtf8Byte str,
const JSize  byteCount,
JInteger value,
const JSize  origBase = 10 
)
static

Convert string to a signed integer. Returns true if successful.

base must be between 2 and 36 inclusive. If the string begins with 0x or 0X, base is forced to 16.

◆ ConvertToInteger() [2/3]

bool JString::ConvertToInteger ( const JUtf8Byte str,
JInteger value,
const JSize  base = 10 
)
inlinestatic

◆ ConvertToInteger() [3/3]

bool JString::ConvertToInteger ( JInteger value,
const JSize  base = 10 
) const
inline

◆ ConvertToUInt() [1/3]

bool JString::ConvertToUInt ( const JUtf8Byte str,
const JSize  byteCount,
JUInt value,
const JSize  origBase = 10 
)
static

Convert string to an unsigned integer. Returns true if successful.

base must be between 2 and 36 inclusive. If the string begins with 0x or 0X, base is forced to 16.

◆ ConvertToUInt() [2/3]

bool JString::ConvertToUInt ( const JUtf8Byte str,
JUInt value,
const JSize  base = 10 
)
inlinestatic

◆ ConvertToUInt() [3/3]

bool JString::ConvertToUInt ( JUInt value,
const JSize  base = 10 
) const
inline

◆ CopyNormalizedBytes()

JSize JString::CopyNormalizedBytes ( const JUtf8Byte source,
const JSize  maxBytes,
JUtf8Byte destination,
const JSize  capacity 
)
static

This function processes at most maxBytes from source and places the normalized characters into destination. (Normalization greatly simplifies all further operations on the string.)

The return value is the number of bytes inserted into destination. Because of normalization, this may be less than the number of input bytes processed.

destination is guaranteed to be nullptr terminated. The name capacity should remind you that there must also be room for a null terminator - at most capacity-1 bytes are actually inserted.

◆ CountBytes()

JSize JString::CountBytes ( const JUtf8Byte str,
const JSize  characterCount 
)
static

◆ CountBytesBackward()

bool JString::CountBytesBackward ( const JUtf8Byte str,
const JSize  byteOffset,
const JSize  characterCount,
JSize byteCount 
)
static

Works backwards from the given offset. Returns false if it prematurely hits the start of the string.

◆ CountCharacters() [1/3]

JSize JString::CountCharacters ( const JUtf8Byte str)
static

◆ CountCharacters() [2/3]

JSize JString::CountCharacters ( const JUtf8Byte str,
const JSize  byteCount 
)
inlinestatic

◆ CountCharacters() [3/3]

JSize JString::CountCharacters ( const JUtf8Byte str,
const JUtf8ByteRange range 
)
static

◆ DecodeBase64()

bool JString::DecodeBase64 ( JString str) const

◆ EncodeBase64()

JString JString::EncodeBase64 ( ) const

◆ EndsWith() [1/8]

bool JString::EndsWith ( const JString str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ EndsWith() [2/8]

bool JString::EndsWith ( const JString str,
const JCharacterRange range,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ EndsWith() [3/8]

bool JString::EndsWith ( const JUtf8Byte str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ EndsWith() [4/8]

bool JString::EndsWith ( const JUtf8Byte str,
const JSize  byteCount,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ EndsWith() [5/8]

bool JString::EndsWith ( const JUtf8Byte str,
const JUtf8ByteRange range,
const Case  caseSensitive = kCompareCase 
) const

◆ EndsWith() [6/8]

bool JString::EndsWith ( const JUtf8Character c,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ EndsWith() [7/8]

bool JString::EndsWith ( const std::string &  str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ EndsWith() [8/8]

bool JString::EndsWith ( const std::string &  str,
const JUtf8ByteRange range,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ GetByteCount()

JSize JString::GetByteCount ( ) const
inline

◆ GetBytes()

const JUtf8Byte * JString::GetBytes ( ) const

◆ GetCharacterCount()

JSize JString::GetCharacterCount ( ) const
inline

◆ GetFirstCharacter()

JUtf8Character JString::GetFirstCharacter ( ) const

◆ GetLastCharacter()

JUtf8Character JString::GetLastCharacter ( ) const

◆ GetMinLgSize()

JSize JString::GetMinLgSize ( ) const
inline

◆ GetRawBytes()

const JUtf8Byte * JString::GetRawBytes ( ) const
inline

NOT guaranteed to be nullptr terminated

◆ GetUnterminatedBytes()

const JUtf8Byte * JString::GetUnterminatedBytes ( ) const
inlineprotected

◆ IsAscii()

bool JString::IsAscii ( ) const
inline

◆ IsEmpty() [1/3]

bool JString::IsEmpty ( ) const
inline

◆ IsEmpty() [2/3]

bool JString::IsEmpty ( const JString s)
inlinestatic

◆ IsEmpty() [3/3]

bool JString::IsEmpty ( const JUtf8Byte s)
inlinestatic

◆ IsFloat() [1/3]

bool JString::IsFloat ( ) const
inline

Returns true if we can convert ourselves to a number.

◆ IsFloat() [2/3]

bool JString::IsFloat ( const JUtf8Byte str)
inlinestatic

◆ IsFloat() [3/3]

bool JString::IsFloat ( const JUtf8Byte str,
const JSize  byteCount 
)
inlinestatic

◆ IsHexValue() [1/3]

bool JString::IsHexValue ( ) const
inline

◆ IsHexValue() [2/3]

bool JString::IsHexValue ( const JUtf8Byte str)
inlinestatic

◆ IsHexValue() [3/3]

bool JString::IsHexValue ( const JUtf8Byte str,
const JSize  byteCount 
)
static

Returns true if string begins with whitespace+"0x".

◆ IsInteger() [1/3]

bool JString::IsInteger ( const JSize  base = 10) const
inline

◆ IsInteger() [2/3]

bool JString::IsInteger ( const JUtf8Byte str,
const JSize  base = 10 
)
inlinestatic

◆ IsInteger() [3/3]

bool JString::IsInteger ( const JUtf8Byte str,
const JSize  byteCount,
const JSize  base 
)
inlinestatic

◆ IsOwner()

bool JString::IsOwner ( ) const
inline

◆ IsUInt() [1/3]

bool JString::IsUInt ( const JSize  base = 10) const
inline

◆ IsUInt() [2/3]

bool JString::IsUInt ( const JUtf8Byte str,
const JSize  base = 10 
)
inlinestatic

◆ IsUInt() [3/3]

bool JString::IsUInt ( const JUtf8Byte str,
const JSize  byteCount,
const JSize  base 
)
inlinestatic

◆ IsValid() [1/2]

bool JString::IsValid ( const JUtf8Byte s)
inlinestatic

◆ IsValid() [2/2]

bool JString::IsValid ( const JUtf8Byte s,
const JUtf8ByteRange range 
)
static

◆ MatchCase() [1/7]

bool JString::MatchCase ( const JString source,
const JCharacterRange sourceRange 
)

◆ MatchCase() [2/7]

bool JString::MatchCase ( const JString source,
const JCharacterRange sourceRange,
const JCharacterRange destRange 
)

◆ MatchCase() [3/7]

bool JString::MatchCase ( const JUtf8Byte source,
const JUtf8ByteRange sourceRange 
)

◆ MatchCase() [4/7]

bool JString::MatchCase ( const JUtf8Byte source,
const JUtf8ByteRange sourceRange,
const JCharacterRange destRange 
)

◆ MatchCase() [5/7]

bool JString::MatchCase ( const JUtf8Byte source,
const JUtf8ByteRange sourceRange,
const JUtf8ByteRange destRange 
)
protected

Adjusts the case of destRange to match the case of sourceRange in source. Returns true if any changes were made.

If sourceRange and destRange have the same number of characters, we match the case of each character individually.

Otherwise:

If both first characters are letters, the first letter of destRange is adjusted to the same case as the first character of sourceRange.

If the rest of sourceRange contains at least one alphabetic character and all its alphabetic characters have the same case, all the alphabetic characters in destRange are coerced to that case.

◆ MatchCase() [6/7]

bool JString::MatchCase ( const std::string &  source,
const JUtf8ByteRange sourceRange 
)

◆ MatchCase() [7/7]

bool JString::MatchCase ( const std::string &  source,
const JUtf8ByteRange sourceRange,
const JCharacterRange destRange 
)

◆ Normalize()

JSize JString::Normalize ( const JUtf8Byte source,
const JSize  byteCount,
JUtf8Byte **  destination 
)
static

Allocates space and returns the normalized version of the input characters.

 The caller must delete [] the result!

◆ operator delete()

void JString::operator delete ( void *  memory)
noexcept

◆ operator new() [1/3]

void * JString::operator new ( size_t  size,
const JUtf8Byte file,
const JUInt32  line,
const int  type,
const bool  assert 
)
noexcept

◆ operator new() [2/3]

void * JString::operator new ( size_t  sz)
noexcept

If a JString is constructed on the heap, we need to cancel out the Name Return Value Optimization to ensure that we own the data.

◆ operator new() [3/3]

void * JString::operator new ( size_t  sz,
const bool  forceShallow 
)
noexcept

◆ operator+=() [1/4]

JString & JString::operator+= ( const JString str)
inline

◆ operator+=() [2/4]

JString & JString::operator+= ( const JUtf8Byte str)
inline

◆ operator+=() [3/4]

JString & JString::operator+= ( const JUtf8Character c)
inline

◆ operator+=() [4/4]

JString & JString::operator+= ( const std::string &  str)
inline

◆ operator=() [1/4]

JString & JString::operator= ( const JString str)
inline

◆ operator=() [2/4]

JString & JString::operator= ( const JUtf8Byte str)
inline

◆ operator=() [3/4]

JString & JString::operator= ( const JUtf8Character c)
inline

◆ operator=() [4/4]

JString & JString::operator= ( const std::string &  str)
inline

◆ Prepend() [1/5]

void JString::Prepend ( const JString str)
inline

◆ Prepend() [2/5]

void JString::Prepend ( const JUtf8Byte str)
inline

◆ Prepend() [3/5]

void JString::Prepend ( const JUtf8Byte str,
const JSize  byteCount 
)

◆ Prepend() [4/5]

void JString::Prepend ( const JUtf8Character c)
inline

◆ Prepend() [5/5]

void JString::Prepend ( const std::string &  str)
inline

◆ Print()

void JString::Print ( std::ostream &  output) const

Display the text in such a way that the user can understand it. (i.e. don't display it in quotes, and don't use the internal ")

◆ PrintHex()

void JString::PrintHex ( std::ostream &  output) const

Display the hex bytes.

◆ RangeValid() [1/2]

bool JString::RangeValid ( const JCharacterRange range) const
inline

◆ RangeValid() [2/2]

bool JString::RangeValid ( const JUtf8ByteRange range) const
inline

◆ Read()

void JString::Read ( std::istream &  input,
const JSize  count 
)

Read the specified number of characters from the stream. This replaces the current contents of the string.

◆ ReadDelimited()

void JString::ReadDelimited ( std::istream &  input)

Read a string of quote delimited characters from the stream. Double quote (") and backslash () characters that are part of the string must be preceded by a backslash. This replaces the current contents of the string.

◆ ReplaceBytes()

void JString::ReplaceBytes ( const JUtf8ByteRange replaceRange,
const JUtf8Byte stringToInsert,
const JSize  insertByteCount 
)
protected

Replace the specified range with the given bytes.

It is safe to pass in "nullptr, 0" for the insertion, to do a remove.

◆ SearchBackward()

bool JString::SearchBackward ( const JUtf8Byte str,
const JSize  byteCount,
const Case  caseSensitive,
JIndex byteIndex 
) const
protected

Return the byte index corresponding to the start of the previous occurrence of the given sequence in our string, starting at *byteIndex.

In: *byteIndex is first location to consider Out: If function returns true, *byteIndex is location of prev occurrence. Otherwise, *byteIndex is zero.

◆ SearchForward()

bool JString::SearchForward ( const JUtf8Byte str,
const JSize  byteCount,
const Case  caseSensitive,
JIndex byteIndex 
) const
protected

Return the byte index corresponding to the start of the next occurrence of the given sequence in our string, starting at *byteIndex.

In: *byteIndex is first location to consider Out: If function returns true, *byteIndex is location of next occurrence. Otherwise, *byteIndex is beyond end of string.

◆ Set() [1/8]

void JString::Set ( const JString str)

◆ Set() [2/8]

void JString::Set ( const JString str,
const JCharacterRange range 
)

◆ Set() [3/8]

void JString::Set ( const JUtf8Byte str)
inline

◆ Set() [4/8]

void JString::Set ( const JUtf8Byte str,
const JSize  byteCount 
)
inline

◆ Set() [5/8]

void JString::Set ( const JUtf8Byte str,
const JUtf8ByteRange range 
)
inline

◆ Set() [6/8]

void JString::Set ( const JUtf8Character c)
inline

◆ Set() [7/8]

void JString::Set ( const std::string &  str)
inline

◆ Set() [8/8]

void JString::Set ( const std::string &  str,
const JUtf8ByteRange range 
)
inline

◆ SetIterator()

void JString::SetIterator ( JStringIterator iter) const
protected

◆ SetMinLgSize()

void JString::SetMinLgSize ( const JSize  lgSize)
inline

◆ Split() [1/3]

void JString::Split ( const JRegex separator,
JPtrArray< JString > *  partList,
const JSize  limit = 0,
const bool  includeSeparators = false 
) const

◆ Split() [2/3]

void JString::Split ( const JString separator,
JPtrArray< JString > *  partList,
const JSize  limit = 0,
const bool  includeSeparators = false 
) const

◆ Split() [3/3]

void JString::Split ( const JUtf8Byte separator,
JPtrArray< JString > *  partList,
const JSize  limit = 0,
const bool  includeSeparators = false 
) const
inline

◆ StartsWith() [1/8]

bool JString::StartsWith ( const JString str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ StartsWith() [2/8]

bool JString::StartsWith ( const JString str,
const JCharacterRange range,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ StartsWith() [3/8]

bool JString::StartsWith ( const JUtf8Byte str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ StartsWith() [4/8]

bool JString::StartsWith ( const JUtf8Byte str,
const JSize  byteCount,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ StartsWith() [5/8]

bool JString::StartsWith ( const JUtf8Byte str,
const JUtf8ByteRange range,
const Case  caseSensitive = kCompareCase 
) const

◆ StartsWith() [6/8]

bool JString::StartsWith ( const JUtf8Character c,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ StartsWith() [7/8]

bool JString::StartsWith ( const std::string &  str,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ StartsWith() [8/8]

bool JString::StartsWith ( const std::string &  str,
const JUtf8ByteRange range,
const Case  caseSensitive = kCompareCase 
) const
inline

◆ ToLower()

void JString::ToLower ( )

Convert all characters to lower case.

◆ ToUpper()

void JString::ToUpper ( )

Convert all characters to upper case.

◆ TrimWhitespace()

void JString::TrimWhitespace ( )

Trim leading and trailing whitespace from ourselves.

TODO: utf8

Friends And Related Symbol Documentation

◆ JStringIterator

friend class JStringIterator
friend

◆ operator<<

std::ostream & operator<< ( std::ostream &  output,
const JString aString 
)
friend

◆ operator>>

std::istream & operator>> ( std::istream &  input,
JString aString 
)
friend

The string data is delimited by double quotes: "this is a string".

To include double quotes in a string, use " To include a backslash in a string, use \

An exception is made if the streams are std::cin or std::cout. For input, characters are simply read until 'return' is pressed. For output, Print() is used.

Member Data Documentation

◆ empty

const JString JString::empty
static

◆ kDefSigDigitCount

const JInteger JString::kDefSigDigitCount = 16
static

◆ kPrecisionAsNeeded

const JInteger JString::kPrecisionAsNeeded = -1
static

◆ newline

const JString JString::newline
static

◆ theDefaultMinLgSize

JSize JString::theDefaultMinLgSize = 5
static

The documentation for this class was generated from the following files: