InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WideString Class Reference

#include <WideString.h>

Inheritance diagram for WideString:
UnicodeSavvyString

Public Types

typedef object_type data_type
 
typedef UTF16TextChar & reference_raw
 
typedef const UTF16TextChar & const_reference_raw
 
typedef UTF16TextChar value_type_raw
 
typedef std::ptrdiff_t difference_type
 
typedef UTF16TextChar * pointer_raw
 
typedef const UTF16TextChar * const_pointer_raw
 
typedef UTF16TextChar * iterator_raw
 
typedef const UTF16TextChar * const_iterator_raw
 
typedef K2Reverse_iterator
< iterator_raw, value_type_raw,
difference_type, pointer_raw,
reference_raw > 
reverse_iterator_raw
 
typedef K2Reverse_iterator
< const_iterator_raw,
value_type_raw,
difference_type,
const_pointer_raw,
const_reference_raw > 
const_reverse_iterator_raw
 
typedef UTF32TextCharreference
 
typedef const UTF32TextCharconst_reference
 
typedef UTF32TextChar value_type
 
typedef UTF32TextCharpointer
 
typedef const UTF32TextCharconst_pointer
 
typedef WideStringConstUTF32Iter const_iterator
 
typedef K2Reverse_iterator
< const_iterator, value_type,
difference_type, const_pointer,
const_iterator::value_type > 
const_reverse_iterator
 
- Public Types inherited from UnicodeSavvyString
typedef int32 size_type
 
typedef std::ptrdiff_t difference_type
 
typedef UTF16TextChar code_value
 
typedef UTF32TextChar code_point
 
typedef code_value * code_value_iterator
 
typedef code_value const * const_code_value_iterator
 
typedef const UnicodeSavvyStringconst_reference
 
typedef UTF16TextChar value_type
 

Public Member Functions

 WideString (WideString::const_pointer_raw s, int32 len=kMaxInt32, int32 numChars=-1)
 
 WideString (const WideString::const_iterator &iter, int32 numChars)
 
 WideString (const WideString &w)
 
 WideString (WideString &&other) noexcept=default
 
 WideString (ConstCString string, int32 numChars=-1)
 
 WideString (const PMString &s)
 
 WideString (const wchar_t *s, int32 len=kMaxInt32)
 
template<class IteratorType >
 WideString (IteratorType b, IteratorType e, size_type nCodePoints=0)
 
 WideString (adobe::move_from< WideString > other)
 
 ~WideString ()
 
void SetString (const WideString &s)
 
void SetString (const WideString::const_iterator &iter, int32 numChars)
 
void SetCString (ConstCString C, bool16 convertEmbeddedUnicode=kFalse, int32 numChars=-1)
 
void SetX16String (WideString::const_pointer_raw x, int32 len=kMaxInt32, int32 numChars=-1)
 
void SetX16String (const wchar_t *s, int32 len=kMaxInt32, int32 numChars=-1)
 
iterator_raw begin_raw ()
 
const_iterator_raw begin_raw () const
 
iterator_raw end_raw ()
 
const_iterator_raw end_raw () const
 
reverse_iterator_raw rbegin_raw ()
 
const_reverse_iterator_raw rbegin_raw () const
 
reverse_iterator_raw rend_raw ()
 
const_reverse_iterator_raw rend_raw () const
 
const_iterator begin () const
 
const_iterator end () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
int32 UTF16IndexToCodePointIndex (int32 index) const
 
bool16 empty () const
 
void Clear ()
 
int32 Length () const
 
bool16 IsNull () const
 
UTF32TextChar GetChar (int32 pos) const
 
UTF32TextChar LastChar () const
 
UTF32TextChar FirstChar () const
 
void push_back (WideString::value_type c)
 
void Append (const WideString &s)
 
void Append (const WideString::const_iterator &iter, int32 numChars)
 
void Append (WideString::const_pointer_raw buf, int32 n, int32 numChars=-1)
 
WideStringappend (WideString::const_pointer_raw s, size_type nCodeValues, size_type nCodePoints=0)
 
WideStringreplace (const WideString::const_iterator &b, const WideString::const_iterator &e, const WideString &s)
 
WideStringreplace (const WideString::const_iterator &b, const WideString::const_iterator &e, const WideString::const_iterator &br, const WideString::const_iterator &er)
 
WideStringerase (const WideString::const_iterator &b, const WideString::const_iterator &e)
 
void Append (WideString::value_type c32)
 
void Insert (const WideString &s, int32 position=0, int32 count=kMaxInt32)
 
void Insert (WideString::const_pointer_raw buf, int32 len, int32 pos=0)
 
void Insert (WideString::value_type c, int32 pos=0)
 
WideStringSubstring (int32 position, int32 count=kMaxInt32) const
 
WideStringGetItem (const WideString &delimiter, const int32 nItem) const
 
void remove_raw (int32 utf16Pos, int32 utf16Count)
 
void RemoveCodePoints (int32 startCodePointIndex, int32 numCodePoints)
 
int32 IndexOf (const WideString &keyString, int32 position=0) const
 
int32 IndexOf (WideString::value_type c, int32 position=0) const
 
bool16 Contains (const WideString &key, int32 pos=0) const
 
void Shrink (bool16 maxshrink=kFalse)
 
WideStringoperator= (const WideString &other)
 
WideStringoperator= (WideString &&other) noexcept
 
WideStringoperator= (WideString::const_pointer_raw copy)
 
const UTF32TextChar operator[] (int32 index) const
 
void SetChar (int32 index, WideString::value_type c32)
 
int32 compare (const WideString &s) const
 
template<class IteratorType >
WideStringassign (IteratorType b, IteratorType e, size_type nCodePoints=0)
 
WideStringassign (WideString::const_pointer_raw src, size_type nCodeValues, size_type nCodePoints=0)
 
bool16 operator>= (const WideString &s) const
 
bool16 operator> (const WideString &s) const
 
bool16 operator<= (const WideString &s) const
 
bool16 operator< (const WideString &s) const
 
bool16 operator== (const WideString &s) const
 
bool16 operator!= (const WideString &s) const
 
bool16 operator== (WideString::const_pointer_raw b) const
 
bool16 operator!= (const UTF16TextChar *b) const
 
WideStringoperator+= (WideString::value_type c)
 
WideStringoperator+= (const WideString &s)
 
uint32 Hash (void) const
 
void ToLower ()
 
void ToUpper ()
 
int32 Strip (WideString::value_type c)
 
void BuildFromSystemString (const PMString &ss)
 
void GetSystemString (PMString *ss) const
 
void ReadWrite (IPMStream *s)
 
- Public Member Functions inherited from UnicodeSavvyString
bool16 HasMultiWordUnicode () const
 
size_type CharCount () const
 
size_type NumUTF16TextChars () const
 
size_type capacity (void) const
 
void reserve (size_type newCapacity)
 
void resize (size_type newSize, code_value fill=code_value())
 
void clear ()
 
const UTF16TextChar * GrabUTF16Buffer (int32 *numUTF16s) const
 
int32 CodePointIndexToUTF16Index (int32 index) const
 
void Truncate (CharCounter count)
 
void Remove (int32 position, CharCounter count)
 
UTF32TextChar GetUTF32TextChar (int32 pos) const
 
const_code_value_iterator begin () const
 
const_code_value_iterator end () const
 

Static Public Attributes

static const boost::shared_ptr
< WideString
kNil_shared_ptr
 

Additional Inherited Members

- Protected Types inherited from UnicodeSavvyString
enum  { kMaxSmallString = 23 }
 
- Protected Member Functions inherited from UnicodeSavvyString
 UnicodeSavvyString (adobe::move_from< UnicodeSavvyString > other)
 
 UnicodeSavvyString (UnicodeSavvyString &&other) noexcept
 
void move_from (UnicodeSavvyString &other) noexcept
 
template<class IteratorType >
 UnicodeSavvyString (IteratorType b, IteratorType e, size_type nCodePoints=0)
 
int32 CountChars () const
 
int32 CountCharsUtil (const UTF16TextChar *buffer, int32 bufferLength) const
 
void InsertGap (uint32 wordWiseIndex, size_type numberOfSpaces)
 
void RemoveGap (uint32 wordWiseIndex, size_type numberOfSpaces)
 
void InsertUTF32TextChar (UTF32TextChar c, int32 pos=0)
 
void InsertUTF16String (const UTF16TextChar *buf, int32 len, int32 position=0)
 
void AppendUTF32TextChar (UTF32TextChar c32)
 
void CopyFrom (const UnicodeSavvyString &other)
 
bool16 operator== (const UnicodeSavvyString &s) const
 
template<class IteratorType >
UnicodeSavvyStringassign (IteratorType b, IteratorType e, size_type nCodePoints=0)
 
UnicodeSavvyStringreplace (size_type pos, size_type n1, code_value const *s, size_type n2)
 
UnicodeSavvyStringappend (code_value const *s, size_type nCodeValues, size_type nCodePoints=0)
 
UTF32TextChar surro_GetUTF32TextChar (int32 pos) const
 
const UTF16TextChar * ConstBuffer () const
 
void insert_safe (code_value_iterator i, const_code_value_iterator sb, const_code_value_iterator se)
 
void erase_safe (code_value_iterator b, code_value_iterator e)
 
void replace_safe (code_value_iterator b, code_value_iterator e, const_code_value_iterator sb, const_code_value_iterator se)
 
template<class InputIterator >
void assign_impl (InputIterator b, InputIterator e, size_type nCodePoints, std::input_iterator_tag)
 
template<class FwdIterator >
void assign_impl (FwdIterator b, FwdIterator e, size_type nCodePoints, std::forward_iterator_tag)
 
bool16 UnicodeBufferIsValid () const
 
UTF16TextChar * GetBufferForWriting (size_type size)
 
- Protected Attributes inherited from UnicodeSavvyString
StringStoragefStorage
 
UTF16TextChar fSmallStorage [kMaxSmallString+1]
 
size_type fUTF16BufferLength
 
size_type fNumChars
 

Detailed Description

WideString is the main Unicode string storage class.

Constructor & Destructor Documentation

template<class IteratorType >
WideString::WideString (IteratorType b,
IteratorType e,
size_type nCodePoints = 0 
)
inline

Constructs the string using a range of code values [b, e). The code values in the range need to be UTF16 or UTF32 encoded.

Parameters
b[IN] - beginning of the range.
e[IN] - end of the range (one past last one).
nCodePoints[IN, OPTIONAL] - number of code points in the range. This parameter can be used for optimization purposes, if the caller knows the number of code points represented in the range.
WideString::WideString (adobe::move_from< WideStringother)
inline

Movable constructor - assumes ownership of the remote part.

WideString::~WideString ()

Destructor.

Member Function Documentation

WideString& WideString::append (WideString::const_pointer_raw s,
size_type nCodeValues,
size_type nCodePoints = 0 
)
inline

Appends the code values from the C-array s at the end of the current string.

Parameters
s[IN] - C-array of code values that will be added to this string.
nCodeValues[IN] - number of code values to be added.
nCodePoints[IN, OPTIONAL] - number of code points that nCodeValues represent. This can be used for optimization purposes if the caller knows how many code points are added.
Returns
reference to this string.
template<class IteratorType >
WideString& WideString::assign (IteratorType b,
IteratorType e,
size_type nCodePoints = 0 
)
inline

Assigns to the string the code values in the specified range [b, e). The code values in the range need to be UTF16 or UTF32 encoded.

Parameters
b[IN] - beginning of the range.
e[IN] - end of the range (one past last one).
nCodePoints[IN, OPTIONAL] - number of code points in the range. This parameter can be used for optimization purposes, if the caller knows the number of code points represented in the range.
WideString& WideString::assign (WideString::const_pointer_raw src,
size_type nCodeValues,
size_type nCodePoints = 0 
)
inline

Assigns to the string nCodeValues from the array indicated by src. The code values in the range need to be UTF16 encoded.

Parameters
src[IN] - array of UTF16 code values. It must contain at least nCodeValues elements.
nCodeValues[IN, OPTIONAL] - number of code values to be copied from src.
nCodePoints[IN, OPTIONAL] - number of code points represented in the specified range.
const_iterator WideString::begin () const
inline

These are the methods on the smart UTF32 and surrogate-savvy iterator. Since the UTF32TextChar handed back cannot be changed (it is calculated), there is no non-const version of the iterator.

iterator_raw WideString::begin_raw ()

the next set return a pointer to the buffer still owned by the object fast and dangerous...you'd better not be modifying format or content of the object while the pointer is in use. The point of these is to lightly wrap system strings while avoiding a round trip copy. This CAN do slow things if you HAVE a cstring and ask for a pstring, the object will turn itself into something that can return a pstring. These work best when you ask for a format that is easy to convert to.

You cannot change the number of characters in the buffer using iterators. If you use the raw non-const iterators on a string that has surrogates, you cannot change a surrogate value to a non-surrogate, and vice-versa.

WideString& WideString::erase (const WideString::const_iteratorb,
const WideString::const_iteratore 
)
inline

Removes the code points in range [b, e).

Parameters
b[IN] - begining of the range where erase starts.
e[IN] - end of the range to be erased.
Returns
reference to this string.
WideString* WideString::GetItem (const WideStringdelimiter,
const int32 nItem 
) const

Returns the specified token/item of a string, given a single delimiter

Parameters
delimiterIN The string to use as a delimiter
nItemIN The one based item number for the the desired item
Returns
A pointer to a string you need to deallocate, typically via k2::scoped_ptr. If the item does not exist (i.e. nItem is too low or high) then nil will be returned instead of a valid object.
uint32 WideString::Hash (void ) const

provide a binary hash value based on numeric codes

int32 WideString::Length (void ) const
inline

DEPRECATED: Use CharCount() instead

WideString& WideString::operator= (const WideStringother)
inline

Copy assignment operator.

WideString& WideString::operator= (WideString && other)
inlinenoexcept

Move assignment operator.

const UTF32TextChar WideString::operator[] (int32 index) const
inline

CANNOT set using this routine! use SetChar()

WideString& WideString::replace (const WideString::const_iteratorb,
const WideString::const_iteratore,
const WideStrings 
)
inline

Replaces the code points in range [b, e) with the string s. The function grows the string if necessary to accomodate for the replacement string. Note: to remove the specified range, use an empty string. To insert or append characters without removing anything, use the same iterator for b and e.

Parameters
b[IN] - begining of the range where replacement starts.
e[IN] - end of the range to be replaced.
s[IN] - replacement string whose content will replace the [b, e) range.
Returns
reference to this string.
WideString& WideString::replace (const WideString::const_iteratorb,
const WideString::const_iteratore,
const WideString::const_iteratorbr,
const WideString::const_iteratorer 
)

Replaces the code points in range [b, e) with the code points in the range [br, er). The function grows the string if necessary to accomodate for the replacement string. Note: to remove the specified range, use an empty range for replacement (i.e. br == er). To insert or append characters without removing anything, use the same iterator for b and e.

Parameters
b[IN] - begining of the range where replacement starts.
e[IN] - end of the range to be replaced.
br[IN] - begin of replacement range.
er[IN] - begin of replacement range.
Returns
reference to this string.
void WideString::SetCString (ConstCString C,
bool16 convertEmbeddedUnicode = kFalse,
int32 numChars = -1 
)

these routines automatically convert to 16 bits. optionally they will also convert embedded unicode sequences, e.g. <2022> (unicode bullet)

void WideString::SetString (const WideStrings)

COPY the data passed in into a new implementation

void WideString::Shrink (bool16 maxshrink = kFalse)

remove extra chunks if false, all extra space if true

int32 WideString::Strip (WideString::value_type c)
inline

remove all instance of char in the string and return the number of chars stripped