avmplus::String Class Reference

#include <StringObject.h>

Inheritance diagram for avmplus::String:

avmplus::AvmPlusScriptableObject MMgc::RCObject MMgc::GCObject List of all members.
int Compare (String &toCompare)
bool Contains (wchar c)
bool Equals (const wchar *toCompare, int len)
bool FastEquals (const wchar *toCompare, int len)
bool Equals (const char *other8)
static int Compare (const wchar *s1, int len1, const wchar *s2, int len2)
static int Compare (const wchar *s1, const char *s2, int len)

Public Member Functions

 String (const wchar *str, int len)
 String (const char *str, int utf8len, int utf16len)
 String (Stringp s1, Stringp s0)
 String (Stringp s, int pos, int len)
 String (int len)
 ~String ()
UTF8StringtoUTF8String ()
Atom atom () const
virtual Atom toAtom () const
int length () const
 operator const wchar * ()
const wcharc_str ()
wchar operator[] (int index)
wcharlockBuffer ()
void unlockBuffer (int newLen)
void unlockBuffer ()
Stringp toUpperCase ()
Stringp toLowerCase ()
void setInterned (AvmCore *core)
bool isWhitespace ()
int isInterned () const
double toNumber ()
int indexOf (Stringp s, int i=0)
int indexOfDouble (Stringp s, double i=0)
int lastIndexOf (Stringp s, int i=0x7fffffff)
int lastIndexOfDouble (Stringp s, double i=0x7fffffff)
Stringp charAt (int i=0)
Stringp charAtDouble (double i=0)
double charCodeAt (int i)
double charCodeAtDouble (double i)
int localeCompare (Stringp other)
Stringp substring (int i_start, int i_end)
Stringp substringDouble (double d_start, double d_end)
Stringp slice (int dStart, int dEnd)
Stringp sliceDouble (double dStart, double dEnd)
Stringp substr (int dStart, int dEnd)
Stringp substrDouble (double dStart, double dEnd)
Atom getIntAtom () const
StringBufallocBuf (int numChars)
wchargetData () const
void setBuf (StringBuf *buf)

Static Public Member Functions

static bool isSpace (wchar ch)
static wchar wCharToUpper (wchar ch)
static wchar wCharToLower (wchar ch)
static int Length (const wchar *str)
static int Length (const char *str)

Private Member Functions

Stringp getPrefix () const
uint32 getOffset () const
bool hasPrefix () const
bool hasOffset () const
bool needsNormalization () const
void normalize ()
void generateIntegerEquivalent (AvmCore *core)
void setPrefixOrOffsetOrNumber (uintptr value)

Private Attributes

int m_length
StringBufm_buf
uintptr m_prefixOrOffsetOrNumber

Static Private Attributes

static const wchar lowerCaseBase []
static const wchar upperCaseBase []
static const wchar lowerCaseConversion []
static const wchar upperCaseConversion []
static const unsigned char tolower_map []
static const unsigned char toupper_map []

Classes

class  StringBuf

Detailed Description

A string in UTF-16 encoding. This is the basic string class used by AVM+ code.

Definition at line 103 of file StringObject.h.


Constructor & Destructor Documentation

avmplus::String::String const wchar str,
int  len
 

Definition at line 100 of file StringObject.cpp.

References AvmAssert, and MMGC_MEM_TYPE.

Referenced by charAt(), slice(), sliceDouble(), substr(), substrDouble(), substring(), substringDouble(), toLowerCase(), and toUpperCase().

00102         : AvmPlusScriptableObject(kStringType)
00103 #endif // DEBUGGER
00104     {
00105         AvmAssert(len >= 0);
00106         m_length = len;
00107         MMGC_MEM_TYPE(this);
00108         setBuf(allocBuf(m_length));
00109         memcpy (getData(), str, m_length * sizeof(wchar));
00110         getData()[m_length] = 0;
00111     }

avmplus::String::String const char *  str,
int  utf8len,
int  utf16len
 

Definition at line 83 of file StringObject.cpp.

References AvmAssert, MMGC_MEM_TYPE, and avmplus::UnicodeUtils::Utf8ToUtf16().

00085         : AvmPlusScriptableObject(kStringType)
00086 #endif // DEBUGGER
00087     {
00088         AvmAssert(utf8len >= 0);
00089         AvmAssert(utf16len >= 0);
00090 
00091         MMGC_MEM_TYPE(this);
00092         setBuf(allocBuf(utf16len));
00093         m_length = UnicodeUtils::Utf8ToUtf16((const uint8 *)str, utf8len,
00094                                              getData(), utf16len);
00095         AvmAssert(m_length >= 0);
00096         getData()[m_length] = 0;
00097     }

avmplus::String::String Stringp  s1,
Stringp  s0
 

Definition at line 114 of file StringObject.cpp.

References AvmAssert, length(), m_buf, needsNormalization(), normalize(), and PREFIXFLAG.

00116         : AvmPlusScriptableObject(kStringType)
00117 #endif // DEBUGGER
00118     {
00119         m_length = s1->length() + s2->length();
00120         AvmAssert(m_length >= 0);
00121         setPrefixOrOffsetOrNumber(uintptr(s1) | PREFIXFLAG);
00122         if (s2->needsNormalization()) s2->normalize();
00123         setBuf(s2->m_buf);
00124     }

avmplus::String::String Stringp  s,
int  pos,
int  len
 

Definition at line 127 of file StringObject.cpp.

References MMgc::GC::Alloc(), AvmAssert, MMgc::GC::GetGC(), getOffset(), hasOffset(), hasPrefix(), length(), m_buf, MMGC_MEM_TYPE, normalize(), and OFFSETFLAG.

00129         : AvmPlusScriptableObject(kStringType)
00130 #endif // DEBUGGER
00131     {
00132         // out-of-bounds requests return sensible things
00133         if (pos < 0) {
00134             pos = 0;
00135         }
00136         if (len < 0) {
00137             len = 0;
00138         }
00139 
00140         int s_len = s->length();
00141         if (pos + len > s_len) {
00142             len = s_len - pos;
00143         }
00144         if (pos > s_len) {
00145             len = 0;
00146         }
00147 
00148         AvmAssert(pos >= 0);
00149         AvmAssert(len == 0 || pos + len <= s_len);
00150 
00151         #if 0 // old way
00152         if (s->hasPrefix()) s->normalize();
00153 
00154         m_length = len;
00155         GC* gc = GC::GetGC(this);
00156         MMGC_MEM_TYPE(this);
00157         m_buf = (wchar *) gc->Alloc (sizeof(wchar)*(m_length+1), 0);
00158         memcpy (m_buf, s->m_buf+pos, m_length * sizeof(wchar));
00159         m_buf[m_length] = 0;
00160         m_prefixOrOffsetOrNumber = 0;
00161         #endif
00162 
00163         if (s->hasOffset())
00164         {
00165             m_length = len;
00166             setBuf(s->m_buf);
00167             m_prefixOrOffsetOrNumber = int(((s->getOffset() + pos) << 2) | OFFSETFLAG);
00168             return;
00169         }
00170         else if (s->hasPrefix())
00171         {
00172             Stringp news = s;
00173             while (news->getPrefix() && pos < news->getPrefix()->length())
00174                 news = news->getPrefix();
00175 
00176             int newpos = pos;
00177             int segmentLen = news->length();
00178             if (news->getPrefix())
00179             {
00180                 int prefixLen = news->getPrefix()->length();
00181                 newpos -= prefixLen;
00182                 segmentLen -= prefixLen;
00183             }
00184 
00185             // If our substring is completely contained within our prefix
00186             // string, we can just use that string.  Otherwise we need
00187             // to normalize our string and generate an offset from the
00188             // new string.
00189             if ((newpos + len) <= segmentLen)
00190             {
00191                 m_length = len;
00192                 setBuf(news->m_buf);
00193                 int offset = news->getOffset() + newpos;
00194                 m_prefixOrOffsetOrNumber = int((offset << 2) | OFFSETFLAG);
00195                 return;
00196             }
00197 
00198             s->normalize();
00199         }
00200 
00201         m_length = len;
00202         setBuf(s->m_buf);
00203         m_prefixOrOffsetOrNumber = int((pos << 2) | OFFSETFLAG);
00204     }

avmplus::String::String int  len  ) 
 

Definition at line 71 of file StringObject.cpp.

References AvmAssert, and MMGC_MEM_TYPE.

00073         : AvmPlusScriptableObject(kStringType)
00074 #endif // DEBUGGER
00075     {
00076         AvmAssert(len >= 0);
00077         MMGC_MEM_TYPE(this);
00078         setBuf(allocBuf(len));
00079         m_length = len;
00080     }

avmplus::String::~String  )  [inline]
 

Definition at line 112 of file StringObject.h.

References m_length, NULL, setBuf(), and setPrefixOrOffsetOrNumber().

00113         {
00114 #ifdef MMGC_DRC
00115             setBuf(NULL);
00116             setPrefixOrOffsetOrNumber(0);
00117             m_length = 0;
00118 #endif
00119         }


Member Function Documentation

String::StringBuf * avmplus::String::allocBuf int  numChars  ) 
 

Definition at line 1109 of file StringObject.cpp.

References MMgc::GC::GetGC().

Referenced by normalize().

01110     {
01111         GC* gc = GC::GetGC(this);
01112         return new (gc, sizeof(wchar)*(numChars+1)) StringBuf();
01113     }

Atom avmplus::String::atom  )  const [inline]
 

Returns the Atom equivalent of this String. This is done by or'ing the proper type bits into the pointer.

Definition at line 132 of file StringObject.h.

References avmplus::AtomConstants::kStringType.

Referenced by avmplus::VectorClass::applyTypeArgs(), avmplus::ArrayClass::ArrayClass(), avmplus::RegExpObject::call(), avmplus::XMLObject::callProperty(), avmplus::Toplevel::coerce(), avmplus::AvmCore::constant(), axtam::AXTam::constant(), avmplus::XMLListClass::construct(), avmplus::StringClass::construct(), avmplus::ElementE4XNode::CopyAttributesAndNamespaces(), avmplus::ScriptObject::deleteStringProperty(), avmplus::ScriptObject::delUintProperty(), avmplus::Hashtable::find(), avmshell::SystemClass::getArgv(), avmplus::MethodEnv::getpropertylate_i(), avmplus::ScriptObject::getSlotAtom(), avmplus::ScriptObject::getStringProperty(), avmplus::ScriptObject::getStringPropertyFromProtoChain(), avmplus::ScriptObject::getStringPropertyIsEnumerable(), avmplus::getTraits(), avmplus::ScriptObject::getUintProperty(), avmplus::ScriptObject::hasStringProperty(), avmplus::ScriptObject::hasUintProperty(), avmplus::XMLObject::nextName(), avmplus::XMLListObject::nextName(), avmplus::QNameObject::nextValue(), avmplus::Namespace::nextValue(), avmplus::MethodEnv::op_newobject(), avmplus::RegExpObject::replace(), avmplus::PoolObject::resolveParameterizedType(), avmplus::XMLObject::setLocalName(), avmplus::XMLObject::setName(), avmplus::MethodEnv::setpropertylate_i(), avmplus::ScriptObject::setStringProperty(), avmplus::ScriptObject::setStringPropertyIsEnumerable(), avmplus::ScriptObject::setUintProperty(), avmplus::NativeID::shell_toplevel_a2a_oii_opti2_thunkc(), avmplus::StringClass::split(), avmplus::RegExpObject::stringFromUTF8(), avmplus::AvmCore::throwErrorV(), toAtom(), avmplus::Toplevel::ToAttributeName(), avmplus::XMLObject::toString(), avmplus::XMLListObject::toString(), avmplus::ScriptObject::toString(), and avmplus::XMLObject::XMLObject().

00132 { return AtomConstants::kStringType | (Atom)this; }

const wchar * avmplus::String::c_str  ) 
 

Returns a pointer to the null-terminated string.

Definition at line 973 of file StringObject.cpp.

References getData(), needsNormalization(), and normalize().

Referenced by avmshell::StringBuilderObject::append(), avmplus::ElementE4XNode::CopyAttributesAndNamespaces(), avmplus::Toplevel::decode(), avmplus::Toplevel::encode(), avmplus::Toplevel::escape(), avmplus::Hashtable::find(), axtam::MSIDispatchConsumer::getAtomProperty(), axtam::IDispatchConsumer::getAtomProperty(), avmplus::AvmCore::getIndexFromString(), indexOf(), avmshell::StringBuilderObject::insert(), avmplus::AvmCore::internAllocUtf8(), lastIndexOf(), avmplus::XMLObject::NodeNameEquals(), operator const wchar *(), avmplus::PrintWriter::operator<<(), avmplus::XMLParser::parse(), avmplus::parseDateKeyword(), avmplus::Toplevel::parseFloat(), avmplus::Toplevel::parseInt(), avmplus::StringNullTerminatedUTF8::StringNullTerminatedUTF8(), toLowerCase(), toUpperCase(), avmplus::Toplevel::unescape(), avmplus::RegExpObject::Utf16ToUtf8Index(), and avmplus::XMLObject::XMLObject().

00974     {
00975         // For offset too since our string needs to be null terminated
00976         if (needsNormalization()) normalize();
00977         return getData(); 
00978     }

Stringp avmplus::String::charAt int  i = 0  ) 
 

Definition at line 929 of file StringObject.cpp.

References MMgc::GC::GCV_AVMCORE, getData(), MMgc::GC::GetGC(), MMgc::GC::GetGCContextVariable(), length(), needsNormalization(), and String().

Referenced by charAtDouble().

00930     {
00931         GC *gc = GC::GetGC(this);
00932         AvmCore *core = (AvmCore *) gc->GetGCContextVariable (MMgc::GC::GCV_AVMCORE);
00933         if (iPos >= 0 && iPos < length()) 
00934         {
00935             wchar ch = !this->needsNormalization() ? getData()[iPos] : ((*this)[iPos]);
00936             if (ch < 128)
00937             {
00938                 return core->cachedChars[ch];
00939             }
00940             else
00941             {
00942                 return new (gc) String(this, iPos, 1);
00943             }
00944         }
00945         else
00946         {
00947             return core->kEmptyString;
00948         }
00949     }

Stringp avmplus::String::charAtDouble double  i = 0  ) 
 

Definition at line 951 of file StringObject.cpp.

References charAt(), and avmplus::MathUtils::toInt().

00952     {
00953         dPos = MathUtils::toInt(dPos);
00954         int iPos = (dPos > (double)this->length()) ? this->length() : (int)dPos;
00955         return charAt (iPos);
00956     }

double avmplus::String::charCodeAt int  i  ) 
 

Definition at line 958 of file StringObject.cpp.

References length(), and avmplus::MathUtils::nan().

Referenced by charCodeAtDouble().

00959     {
00960         if (iPos >= 0 && iPos < length())
00961             return (*this)[iPos];
00962         else
00963             return MathUtils::nan();
00964     }

double avmplus::String::charCodeAtDouble double  i  ) 
 

Definition at line 966 of file StringObject.cpp.

References charCodeAt(), and avmplus::MathUtils::toInt().

00967     {
00968         dPos = MathUtils::toInt(dPos);
00969         int iPos = (dPos > (double)this->length()) ? this->length() : (int)dPos;
00970         return charCodeAt (iPos);
00971     }

int avmplus::String::Compare const wchar s1,
const char *  s2,
int  len
[static]
 

Definition at line 232 of file StringObject.cpp.

References AvmAssert.

00233     {
00234         int   ret = 0;
00235         const wchar *dstend = dst + len;
00236 
00237         while(dst < dstend && *src && 0 == (ret = (int)(((wchar)*src) - *dst)) )
00238         {
00239             ++src, ++dst;
00240         }
00241 
00242         if (ret == 0)
00243         {
00244             // catch substring cases (e.g. '1' vs. '104')
00245             if (dst < dstend)
00246             {
00247                 // more chars in dst than src
00248                 AvmAssert(*src == 0);
00249                 ret = -1;
00250             }
00251             else if (*src)
00252             {
00253                 // more chars in src than dst
00254                 AvmAssert(dst == dstend);
00255                 ret = 1;
00256             }
00257             else
00258             {
00259                 // really equal
00260                 AvmAssert(dst == dstend);
00261                 AvmAssert(*src == 0);
00262             }
00263         }
00264 
00265         return ret;
00266     }

int avmplus::String::Compare const wchar s1,
int  len1,
const wchar s2,
int  len2
[static]
 

Compares s1 and s2.

Returns:
= 0 if the strings are identical. < 0 if s1 is less than s2 > 0 if s1 is greater than s2

Definition at line 207 of file StringObject.cpp.

00208     {
00209         int ret = 0;
00210         int count = (dstLen < srcLen) ? dstLen : srcLen;  // choose smaller of two
00211         const wchar *dstend = dst + count;
00212 
00213         while(dst < dstend && 0 == (ret = (int)(*src - *dst)))
00214         {
00215             ++src, ++dst;
00216         }
00217 
00218         // catch substring cases (e.g. '1' vs. '104')
00219         if (ret == 0)
00220         {
00221             if (srcLen < dstLen)
00222                 ret = -1;
00223             else if (srcLen > dstLen)
00224                 ret = 1;
00225             else
00226                 ; // really equal
00227         }
00228         return ret;
00229     }

int avmplus::String::Compare String toCompare  )  [inline]
 

Compare the String with toCompare.

Returns:
= 0 if the strings are identical. < 0 if this string is less than toCompare > 0 if this string is greater than toCompare

Definition at line 215 of file StringObject.h.

References getData(), getOffset(), hasPrefix(), length(), and normalize().

Referenced by avmplus::ArraySort::CaseInsensitiveStringCompare(), avmplus::MathUtils::convertStringToDouble(), Equals(), avmplus::ArraySort::FieldCompare(), avmplus::AvmCore::getIndexFromString(), localeCompare(), avmplus::XMLObject::NodeNameEquals(), avmplus::operator!=(), avmplus::operator<(), avmplus::operator<=(), avmplus::operator==(), avmplus::operator>(), avmplus::operator>=(), and avmplus::ArraySort::StringCompare().

00216         {
00217             if (hasPrefix()) normalize();
00218             if (toCompare.hasPrefix()) toCompare.normalize();
00219 
00220             return String::Compare(getData() + getOffset(), length(), toCompare.getData() + toCompare.getOffset(), toCompare.length());
00221         }

bool avmplus::String::Contains wchar  c  ) 
 

Does String contain wchar?

Returns:
= 0 if the strings are identical. < 0 if this string is less than toCompare > 0 if this string is greater than toCompare

Definition at line 268 of file StringObject.cpp.

References getData(), getOffset(), hasPrefix(), and normalize().

00269     {
00270         if (hasPrefix()) normalize();
00271 
00272         const wchar *p = getData() + getOffset();
00273 
00274         while (*p && (*p != c)) {
00275             p++;
00276         }
00277 
00278         return (*p == c);
00279     }

bool avmplus::String::Equals const char *  other8  )  [inline]
 

Definition at line 266 of file StringObject.h.

References Compare(), getData(), getOffset(), hasPrefix(), length(), and normalize().

00267         { 
00268             if (hasPrefix()) normalize();
00269             return !Compare(getData() + getOffset(), other8, length());
00270         }

bool avmplus::String::Equals const wchar toCompare,
int  len
[inline]
 

Definition at line 233 of file StringObject.h.

References AvmAssert, Compare(), getData(), getOffset(), hasPrefix(), length(), and normalize().

Referenced by avmplus::XMLObject::NodeNameEquals().

00234         {
00235             AvmAssert(toCompare[len]==0);
00236             int sLen = length();
00237             if (len != sLen) return false;
00238             if (hasPrefix()) normalize();
00239             return String::Compare(getData() + getOffset(), sLen, toCompare, len)==0;
00240         }

bool avmplus::String::FastEquals const wchar toCompare,
int  len
[inline]
 

Definition at line 243 of file StringObject.h.

References AvmAssert, getData(), length(), and needsNormalization().

Referenced by avmplus::AvmCore::findString().

00244         {
00245             int sLen = length();
00246             if (len != sLen) return false;
00247             // This is only for intern strings which are never offset or prefix
00248             AvmAssert(needsNormalization() == false);
00249             const wchar *src = getData();
00250 
00251             // !! could we compare two WORDS at a time?  Our toCompare
00252             // string is not necessarily DWORD aligned.  (Offset strings, etc.)
00253 
00254             while (sLen)
00255             {
00256                 sLen--;
00257                 if (src[sLen] != toCompare[sLen])
00258                     return false;
00259             }
00260                 
00261             AvmAssert(sLen == 0);
00262             return true;
00263         }

void avmplus::String::generateIntegerEquivalent AvmCore core  )  [private]
 

Definition at line 1093 of file StringObject.cpp.

References AvmAssert, avmplus::AvmCore::getIndexFromString(), m_prefixOrOffsetOrNumber, avmplus::ScriptObject::MAX_INTEGER_MASK, and NUMBERFLAG.

Referenced by setInterned().

01094     {
01095         AvmAssert(this->isInterned());
01096         AvmAssert(!this->hasOffset());
01097         AvmAssert(!this->hasPrefix());
01098         uint32 index;
01099         (void)core;
01100         if (core->getIndexFromString (this, &index))
01101         {
01102             if (!(index & ScriptObject::MAX_INTEGER_MASK))
01103             {
01104                 m_prefixOrOffsetOrNumber = index<<3 | NUMBERFLAG;
01105             }
01106         }
01107     }

wchar* avmplus::String::getData  )  const [inline]
 

Definition at line 424 of file StringObject.h.

References avmplus::String::StringBuf::m_buf, and m_buf.

Referenced by c_str(), charAt(), Compare(), Contains(), Equals(), FastEquals(), isWhitespace(), lockBuffer(), normalize(), operator[](), toNumber(), and toUTF8String().

00424 { return m_buf->m_buf; }

Atom avmplus::String::getIntAtom  )  const [inline]
 

Definition at line 415 of file StringObject.h.

References avmplus::AtomConstants::kIntegerType, m_prefixOrOffsetOrNumber, NUMBERFLAG, and STRINGFLAGS.

Referenced by avmplus::ScriptObject::deleteAtomProperty(), avmplus::ScriptObject::getAtomProperty(), avmplus::ScriptObject::getAtomPropertyFromProtoChain(), avmplus::ScriptObject::getAtomPropertyIsEnumerable(), avmplus::ScriptObject::hasAtomProperty(), avmplus::ScriptObject::setAtomProperty(), and avmplus::ScriptObject::setAtomPropertyIsEnumerable().

00416         { 
00417             if ((m_prefixOrOffsetOrNumber & STRINGFLAGS) == NUMBERFLAG) 
00418                 return m_prefixOrOffsetOrNumber & ~STRINGFLAGS | kIntegerType;
00419             else 
00420                 return 0; 
00421         };

uint32 avmplus::String::getOffset  )  const [inline, private]
 

Definition at line 383 of file StringObject.h.

References m_prefixOrOffsetOrNumber, OFFSETFLAG, STRINGFLAGS, and avmplus::urshift().

Referenced by Compare(), Contains(), Equals(), isWhitespace(), operator[](), String(), toNumber(), and toUTF8String().

00384         { 
00385             if ((m_prefixOrOffsetOrNumber & STRINGFLAGS) == OFFSETFLAG) 
00386                 return urshift(m_prefixOrOffsetOrNumber & ~STRINGFLAGS, 2); 
00387             else 
00388                 return 0; 
00389         };

Stringp avmplus::String::getPrefix  )  const [inline, private]
 

Definition at line 375 of file StringObject.h.

References m_prefixOrOffsetOrNumber, PREFIXFLAG, and STRINGFLAGS.

Referenced by isWhitespace(), normalize(), operator[](), and setPrefixOrOffsetOrNumber().

00376         { 
00377             if ((m_prefixOrOffsetOrNumber & STRINGFLAGS) == PREFIXFLAG) 
00378                 return Stringp(m_prefixOrOffsetOrNumber & ~STRINGFLAGS); 
00379             else 
00380                 return 0; 
00381         };

bool avmplus::String::hasOffset  )  const [inline, private]
 

Definition at line 392 of file StringObject.h.

References m_prefixOrOffsetOrNumber, OFFSETFLAG, and STRINGFLAGS.

Referenced by String().

00392 { return ((m_prefixOrOffsetOrNumber & STRINGFLAGS) == OFFSETFLAG); };

bool avmplus::String::hasPrefix  )  const [inline, private]
 

Definition at line 391 of file StringObject.h.

References m_prefixOrOffsetOrNumber, PREFIXFLAG, and STRINGFLAGS.

Referenced by Compare(), Contains(), Equals(), normalize(), operator[](), String(), and toUTF8String().

00391 { return ((m_prefixOrOffsetOrNumber & STRINGFLAGS) == PREFIXFLAG); };

int avmplus::String::indexOf Stringp  s,
int  i = 0
 

Definition at line 858 of file StringObject.cpp.

References c_str(), length(), and substr().

Referenced by indexOfDouble().

00859     {
00860         if(!substr)
00861             return -1;
00862 
00863         int sublen = substr->length();
00864         if (iStartPos > this->length()) 
00865             iStartPos = this->length();
00866 
00867         // iRight is the last character in selfString subStr could be found at
00868         // (and further, and there isn't enough of selfString remaining for a match to be possible)
00869         const int iRight = this->length() - sublen; 
00870         
00871         // bug 78346: argv[1] might be less than zero.
00872         // We clamp it to zero for two reasons:
00873         //  1. A movie created prior to this fix with a small negative value probably worked,
00874         //  so let's fix it without breaking them.
00875         //  2. I am told this is what java does.
00876         //
00877         // if (argv[1] > iRight), then we never enter the loop
00878         if (iStartPos < 0) {
00879             iStartPos = 0;
00880         }
00881 
00882         // our substr to find is only one character
00883         if (sublen == 1) 
00884         {
00885             const wchar substrchar = substr->c_str()[0];
00886             const wchar *selfstr = this->c_str();
00887             for ( ; iStartPos <= iRight; iStartPos++)
00888             {
00889                 if (substrchar == selfstr[iStartPos])
00890                 {
00891                     return iStartPos;
00892                 }
00893             }
00894         }
00895         else
00896         {
00897             const wchar *substrstr = substr->c_str();
00898             const wchar *selfstr = this->c_str();
00899             selfstr += iStartPos;
00900             for ( ; iStartPos <= iRight; iStartPos++)
00901             {
00902                 int j;
00903                 for (j = 0; j < sublen; j++)
00904                 {
00905                     if (substrstr[j] != selfstr[j])
00906                     {
00907                         break;
00908                     }
00909                 }
00910 
00911                 if (j == sublen)
00912                 {
00913                     return iStartPos;
00914                 }
00915                 selfstr++;
00916             }
00917         }
00918 
00919         return -1;
00920     }

int avmplus::String::indexOfDouble Stringp  s,
double  i = 0
 

Definition at line 922 of file StringObject.cpp.

References indexOf(), length(), substr(), and avmplus::MathUtils::toInt().

00923     {
00924         dStartPos = MathUtils::toInt(dStartPos);
00925         int iStartPos = (dStartPos > (double)this->length() ? this->length() : (int)dStartPos);
00926         return indexOf (substr, iStartPos);
00927     }

int avmplus::String::isInterned  )  const [inline]
 

Definition at line 306 of file StringObject.h.

References m_length.

Referenced by avmplus::XMLParser::condenseWhitespace(), avmplus::ScriptObject::deleteAtomProperty(), avmplus::ScriptObject::getAtomProperty(), avmplus::ScriptObject::getAtomPropertyFromProtoChain(), avmplus::ScriptObject::getAtomPropertyIsEnumerable(), avmplus::ScriptObject::getStringProperty(), avmplus::ScriptObject::getStringPropertyIsEnumerable(), avmplus::ScriptObject::hasAtomProperty(), avmplus::ScriptObject::hasStringProperty(), avmplus::AvmCore::internString(), avmplus::AvmCore::isName(), avmplus::Namespace::Namespace(), avmplus::ScriptObject::setAtomProperty(), avmplus::ScriptObject::setAtomPropertyIsEnumerable(), avmplus::Multiname::setName(), unlockBuffer(), and avmplus::XMLObject::XMLObject().

00307         {
00308             return m_length & 0x80000000;
00309         }

bool avmplus::String::isSpace wchar  ch  )  [static]
 

Definition at line 1013 of file StringObject.cpp.

Referenced by avmplus::XMLParser::condenseWhitespace(), avmplus::AvmCore::EscapeElementValue(), avmplus::XMLParser::getNext(), and isWhitespace().

01014     {
01015         return (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
01016     }

bool avmplus::String::isWhitespace  ) 
 

Definition at line 1018 of file StringObject.cpp.

References getData(), getOffset(), getPrefix(), util::threadpool::i, isSpace(), and length().

01019     {
01020         Stringp s = this;
01021         do
01022         {
01023             int base = !s->getPrefix() ? 0 : s->getPrefix()->length();
01024             for (int i = s->length()-base-1; i >= 0; i--)
01025                 if (!isSpace(s->getData()[s->getOffset() + i]))
01026                     return false;
01027         }
01028         while ( (s = s->getPrefix()) != 0);
01029         return true;
01030     }

int avmplus::String::lastIndexOf Stringp  s,
int  i = 0x7fffffff
 

Definition at line 1032 of file StringObject.cpp.

References c_str(), length(), and substr().

Referenced by lastIndexOfDouble().

01033     {
01034         int sublen = substr->length();
01035         iStartPos = (iStartPos > this->length()) ? this->length() : iStartPos;
01036 
01037         // iRight is the last character in selfString subStr could be found at
01038         // (and further, and there isn't enough of selfString remaining for a match to be possible)
01039         const int iRight = this->length() - sublen; 
01040         
01041         // bug 78346: argv[1] might be greater than iRight
01042         //  (similar reasons to above apply).
01043         if (iStartPos > iRight) {
01044             iStartPos = iRight;
01045         }
01046 
01047         if (sublen == 0)
01048             return iStartPos;
01049 
01050         const wchar *substrstr = substr->c_str();
01051         const wchar *selfstr = this->c_str() + iStartPos;
01052         for ( ; iStartPos >= 0 ; iStartPos-- )
01053         {
01054             for (int j = 0; j < sublen; j++)
01055             {
01056                 if (substrstr[j] != selfstr[j])
01057                 {
01058                     break;
01059                 }
01060 
01061                 if (j == (sublen - 1))
01062                     return iStartPos;
01063             }
01064 
01065             selfstr--;
01066         }
01067 
01068         return -1;
01069     }

int avmplus::String::lastIndexOfDouble Stringp  s,
double  i = 0x7fffffff
 

Definition at line 1071 of file StringObject.cpp.

References avmplus::MathUtils::isNaN(), lastIndexOf(), length(), substr(), and avmplus::MathUtils::toInt().

01072     {
01073         if (!MathUtils::isNaN(dStartPos))
01074             dStartPos = MathUtils::toInt(dStartPos);
01075         else
01076             dStartPos = this->length();
01077         int iStartPos = (dStartPos > this->length() ? this->length() : (int)dStartPos);
01078         return lastIndexOf (substr, iStartPos);
01079     }

int avmplus::String::Length const char *  str  )  [static]
 

Definition at line 57 of file StringObject.cpp.

00058     {
00059         if (!str) 
00060             return 0;
00061 
00062         int len = 0;
00063         while (*str) {
00064             len++;
00065             str++;
00066         }
00067         return len;
00068     }

int avmplus::String::Length const wchar str  )  [static]
 

Returns the length of str, in # of characters.

Definition at line 44 of file StringObject.cpp.

Referenced by avmplus::MathUtils::convertIntegerToString(), avmplus::ElementE4XNode::CopyAttributesAndNamespaces(), avmplus::AvmCore::newString(), avmplus::PrintWriter::operator<<(), avmplus::Date::toString(), and avmplus::XMLObject::XMLObject().

00045     {
00046         if (!str) 
00047             return 0;
00048 
00049         int len = 0;
00050         while (*str) {
00051             len++;
00052             str++;
00053         }
00054         return len;
00055     }

int avmplus::String::length  )  const [inline]
 

Returns the length of the string in characters. The null terminator is not included.

Definition at line 143 of file StringObject.h.

References m_length.

Referenced by avmshell::StringBuilderObject::append(), avmplus::AvmCore::boolean(), charAt(), charCodeAt(), Compare(), avmplus::AvmCore::concatStrings(), avmplus::XMLParser::condenseWhitespace(), avmplus::NamespaceClass::construct(), avmplus::Toplevel::decode(), avmplus::Toplevel::encode(), Equals(), avmplus::Toplevel::escape(), avmplus::AvmCore::EscapeAttributeValue(), avmplus::AvmCore::EscapeElementValue(), FastEquals(), avmplus::AvmCore::getIndexFromString(), indexOf(), indexOfDouble(), avmshell::StringBuilderObject::insert(), isWhitespace(), avmplus::AvmCore::isXMLName(), lastIndexOf(), lastIndexOfDouble(), avmplus::XMLObject::NodeNameEquals(), normalize(), avmplus::operator!=(), avmplus::operator==(), operator[](), avmplus::Toplevel::parseFloat(), avmplus::Toplevel::parseInt(), slice(), sliceDouble(), avmplus::StringClass::split(), String(), avmplus::StringNullTerminatedUTF8::StringNullTerminatedUTF8(), avmplus::DateClass::stringToDateDouble(), substr(), substrDouble(), substringDouble(), toLowerCase(), toNumber(), toUpperCase(), toUTF8String(), avmplus::Toplevel::unescape(), avmplus::RegExpObject::Utf16ToUtf8Index(), avmplus::RegExpObject::Utf8ToUtf16Index(), and avmplus::XMLObject::XMLObject().

00143                            { 
00144             return m_length & 0x7FFFFFFF; 
00145         }

int avmplus::String::localeCompare Stringp  other  ) 
 

Definition at line 1081 of file StringObject.cpp.

References Compare(), MMgc::GC::GCV_AVMCORE, MMgc::GC::GetGC(), and MMgc::GC::GetGCContextVariable().

01082     {  
01083         if ( !other )
01084         {
01085             GC *gc = GC::GetGC(this);
01086             AvmCore *core = (AvmCore *) gc->GetGCContextVariable (MMgc::GC::GCV_AVMCORE);
01087             other = core->knull;
01088         }
01089 
01090         return other->Compare(*this);
01091     }

wchar * avmplus::String::lockBuffer  ) 
 

This is an advanced method which returns a non-const pointer to the String's internal buffer. This can be used to mutate a string that is known to not have any other references. Use with caution.

Definition at line 1006 of file StringObject.cpp.

References getData(), needsNormalization(), and normalize().

Referenced by avmshell::ByteArrayObject::_toString(), axtam::ByteArrayObject::_toString(), avmplus::XMLParser::condenseWhitespace(), avmplus::StringClass::fromCharCode(), toLowerCase(), toUpperCase(), and avmplus::Toplevel::unescape().

01007     {
01008         // For offset too since our string needs to be null terminated
01009         if (needsNormalization()) normalize();
01010         return (wchar*) getData(); 
01011     }

bool avmplus::String::needsNormalization  )  const [inline, private]
 

Definition at line 394 of file StringObject.h.

References m_prefixOrOffsetOrNumber, and STRINGFLAGS.

Referenced by c_str(), charAt(), FastEquals(), lockBuffer(), normalize(), String(), and toNumber().

00394 { return ((m_prefixOrOffsetOrNumber & STRINGFLAGS) >= 0x2); };

void avmplus::String::normalize  )  [private]
 

Definition at line 282 of file StringObject.cpp.

References allocBuf(), AvmAssert, getData(), getPrefix(), hasPrefix(), length(), avmplus::String::StringBuf::m_buf, MMGC_MEM_TYPE, needsNormalization(), NULL, and setBuf().

Referenced by c_str(), Compare(), Contains(), Equals(), lockBuffer(), operator[](), String(), toNumber(), and toUTF8String().

00283     {
00284         AvmAssert(needsNormalization() == true);
00285         MMGC_MEM_TYPE(this);
00286         StringBuf *newData = allocBuf(length());
00287         if (newData == NULL)
00288             return;
00289         wchar *new_buf = newData->m_buf;
00290         new_buf[length()] = 0;
00291 
00292         if (hasPrefix())
00293         {
00294             // copy suffix strings right to left
00295             Stringp p = this;
00296             for (; p->getPrefix() != 0; p = p->getPrefix())
00297             {
00298                 memcpy(new_buf + p->getPrefix()->length(), p->getData(), sizeof(wchar)*(p->length()-p->getPrefix()->length()));
00299             }
00300 
00301             memcpy(new_buf, p->getData() + p->getOffset(), sizeof(wchar) * p->length());
00302             setBuf(newData);
00303         }
00304         else
00305         {
00306             AvmAssert(hasOffset());
00307             memcpy(new_buf, getData() + getOffset(), sizeof(wchar) * length());
00308             setBuf(newData);
00309         }
00310 
00311         // prefix is left for GC to dispose of
00312         setPrefixOrOffsetOrNumber(0);
00313     }

avmplus::String::operator const wchar *  )  [inline]
 

Operator overload; returns a pointer to the null-terminated string.

Definition at line 151 of file StringObject.h.

References c_str().

00152         {
00153             return c_str(); 
00154         }

wchar avmplus::String::operator[] int  index  ) 
 

Returns the index'th character of the string.

Parameters:
index zero-based index into the string

Definition at line 980 of file StringObject.cpp.

References AvmAssert, getData(), getOffset(), getPrefix(), hasPrefix(), length(), and normalize().

00981     {
00982         AvmAssert(index >=0 && index < length());
00983         if (!hasPrefix())
00984         {
00985             return getData()[index + getOffset()];
00986         }
00987         else
00988         {
00989             AvmAssert (hasPrefix());
00990             normalize();
00991             return getData()[index];
00992 
00993 #if 0 // This is the code if we want to skip the normalizations
00994             // if this is a composite string, find the prefix containing iPos
00995             Stringp s = this;
00996             while (s->getPrefix() && index < s->getPrefix()->length())
00997                 s = s->getPrefix();
00998 
00999             if (s->getPrefix())
01000                 index -= s->getPrefix()->length();
01001             return s->getData()[s->getOffset() + index];
01002 #endif
01003         }
01004     }

void avmplus::String::setBuf StringBuf buf  )  [inline]
 

Definition at line 425 of file StringObject.h.

References MMgc::GC::GetGC(), m_buf, and WBRC.

Referenced by normalize(), and ~String().

00425 { WBRC(MMgc::GC::GetGC(this), this, &m_buf, buf); }

void avmplus::String::setInterned AvmCore core  )  [inline]
 

Definition at line 296 of file StringObject.h.

References generateIntegerEquivalent(), and m_length.

Referenced by avmplus::AvmCore::internAlloc(), and avmplus::AvmCore::internAllocUtf8().

00297         {
00298             m_length |= 0x80000000;
00299             generateIntegerEquivalent (core);
00300         }

void avmplus::String::setPrefixOrOffsetOrNumber uintptr  value  )  [private]
 

Definition at line 1202 of file StringObject.cpp.

References MMgc::GC::GetGC(), getPrefix(), m_prefixOrOffsetOrNumber, PREFIXFLAG, STRINGFLAGS, and MMgc::GC::WriteBarrierNoSubstitute().

Referenced by ~String().

01203      {
01204 #ifdef MMGC_DRC
01205          // first decrement existing prefix
01206          if((m_prefixOrOffsetOrNumber & STRINGFLAGS) == PREFIXFLAG)
01207             getPrefix()->DecrementRef();
01208 #endif
01209          GC::GetGC(this)->WriteBarrierNoSubstitute(this, (void*)value);
01210          m_prefixOrOffsetOrNumber = value;
01211 #ifdef MMGC_DRC
01212          if((value & STRINGFLAGS) == PREFIXFLAG)
01213              getPrefix()->IncrementRef();
01214 #endif
01215      }

Stringp avmplus::String::slice int  dStart,
int  dEnd
 

Definition at line 1131 of file StringObject.cpp.

References avmplus::NativeObjectHelpers::ClampIndexInt(), MMgc::GC::GetGC(), length(), and String().

01132     {
01133         GC *gc = GC::GetGC(this);
01134         int len = this->length();
01135         start = (int)NativeObjectHelpers::ClampIndexInt(start, len); 
01136         end = (int)NativeObjectHelpers::ClampIndexInt(end, len); 
01137         if (end < start)
01138             end = start;
01139 
01140         return new (gc) String(this, start, end-start);
01141     }

Stringp avmplus::String::sliceDouble double  dStart,
double  dEnd
 

Definition at line 1143 of file StringObject.cpp.

References avmplus::NativeObjectHelpers::ClampIndex(), MMgc::GC::GetGC(), length(), String(), and avmplus::MathUtils::toInt().

01144     {
01145         GC *gc = GC::GetGC(this);
01146         int len = this->length();
01147         int start = (int)NativeObjectHelpers::ClampIndex(MathUtils::toInt(d_start), len); 
01148         int end = (int)NativeObjectHelpers::ClampIndex(MathUtils::toInt(d_end), len); 
01149         if (end < start)
01150             end = start;
01151 
01152         return new (gc) String(this, start, end-start);
01153     }

Stringp avmplus::String::substr int  dStart,
int  dEnd
 

Definition at line 1155 of file StringObject.cpp.

References avmplus::NativeObjectHelpers::ClampIndex(), avmplus::NativeObjectHelpers::ClampIndexInt(), MMgc::GC::GetGC(), length(), and String().

Referenced by indexOf(), indexOfDouble(), lastIndexOf(), and lastIndexOfDouble().

01156     {
01157         GC *gc = GC::GetGC(this);
01158         int len = this->length();
01159         start = (int)NativeObjectHelpers::ClampIndexInt(start, len); 
01160         // ClampIndex takes a double (not int or uint) for first parm...
01161         // we must cast these to double before addition, otherwise we
01162         // can have numeric overflow with the default arg (end=0x7fffffff)
01163         // and wrap to negative, which would be bad...
01164 
01165         // Do some sanity checks on our ints to see if they will fall within a valid integer range
01166         // !!@what about negative values?
01167         if (end == 0x7ffffff)           
01168         {
01169             end = len; 
01170         }
01171         else if ((end > 0xffffff) || (start > 0xffffff)) // might overflow - use doubles
01172         {
01173             end = (int)NativeObjectHelpers::ClampIndex(double(end) + double(start), len); 
01174         }
01175         else
01176         {
01177             end = (int)NativeObjectHelpers::ClampIndexInt(end + start, len); 
01178         }
01179 
01180         if (end < start)
01181             end = start;
01182 
01183         return new (gc) String(this, start, end-start);
01184     }

Stringp avmplus::String::substrDouble double  dStart,
double  dEnd
 

Definition at line 1186 of file StringObject.cpp.

References avmplus::NativeObjectHelpers::ClampIndex(), MMgc::GC::GetGC(), length(), String(), and avmplus::MathUtils::toInt().

01187     {
01188         GC *gc = GC::GetGC(this);
01189         int len = this->length();
01190         int start = (int)NativeObjectHelpers::ClampIndex(MathUtils::toInt(d_start), len); 
01191         // ClampIndex takes a double (not int or uint) for first parm...
01192         // we must cast these to double before addition, otherwise we
01193         // can have numeric overflow with the default arg (end=0x7fffffff)
01194         // and wrap to negative, which would be bad...
01195         int end = (int)NativeObjectHelpers::ClampIndex(MathUtils::toInt(d_end) + (double)start, len); 
01196         if (end < start)
01197             end = start;
01198 
01199         return new (gc) String(this, start, end-start);
01200     }

Stringp avmplus::String::substring int  i_start,
int  i_end
 

Definition at line 1115 of file StringObject.cpp.

References avmplus::NativeObjectHelpers::ClampBInt(), MMgc::GC::GetGC(), and String().

01116     {
01117         GC *gc = GC::GetGC(this);
01118         NativeObjectHelpers::ClampBInt(start, end, this->length());
01119         return new (gc) String(this, start, (end-start));
01120     }

Stringp avmplus::String::substringDouble double  d_start,
double  d_end
 

Definition at line 1122 of file StringObject.cpp.

References avmplus::NativeObjectHelpers::ClampB(), MMgc::GC::GetGC(), length(), String(), and avmplus::MathUtils::toInt().

01123     {
01124         GC *gc = GC::GetGC(this);
01125         double start = MathUtils::toInt(d_start);
01126         double end = MathUtils::toInt(d_end);
01127         NativeObjectHelpers::ClampB(start, end, length());
01128         return new (gc) String(this, (int)start, (int)(end-start));
01129     }

virtual Atom avmplus::String::toAtom  )  const [inline, virtual]
 

virtual version of atom():

Implements avmplus::AvmPlusScriptableObject.

Definition at line 137 of file StringObject.h.

References atom().

00137 { return atom(); }

Stringp avmplus::String::toLowerCase  ) 
 

Returns a new string object which is a copy of this string object, with all characters in the string converted to lowercase.

Unicode character classes for uppercase and lowercase are used. The conversion behavior is compliant with the String.toLowerCase method.

Definition at line 809 of file StringObject.cpp.

References c_str(), MMgc::GC::GetGC(), length(), lockBuffer(), String(), unlockBuffer(), and wCharToLower().

Referenced by avmplus::ArraySort::CaseInsensitiveStringCompare(), and avmplus::ArraySort::FieldCompare().

00810     {
00811         GC* gc = GC::GetGC(this);
00812         int len = length();
00813         Stringp out = new (gc) String(len);
00814 
00815         // Flag to detect whether any changes were made
00816         bool changed = false;
00817 
00818         // First, try quick conversion for low ASCII characters.
00819         wchar *dst = out->lockBuffer();
00820         const wchar *src = c_str();
00821         const wchar *end = src + len;
00822         wchar charIn, charOut;
00823         while (src < end) 
00824         {
00825             charIn = *src;
00826             if (charIn >= 0xFF)
00827                 break;
00828 
00829             charOut = String::tolower_map[charIn] ^ charIn;
00830             if (charOut != charIn)
00831                 changed = true;
00832 
00833             *dst++ = charOut;
00834             src++;
00835         }
00836 
00837         // If that didn't work, resume from where we left off
00838         // with slow full Unicode conversion.
00839         while (src < end) 
00840         {
00841             charIn = *src;
00842             charOut = wCharToLower(charIn);
00843             if (charOut != charIn)
00844                 changed = true;
00845 
00846             *dst++ = charOut;
00847             src++;
00848         }
00849         
00850         *dst = 0;
00851         out->unlockBuffer();
00852 
00853         // Return new string.  If nothing changed, return old
00854         // string (the new string will be GC'd)
00855         return changed ? out : this;
00856     }

double avmplus::String::toNumber  )  [inline]
 

Definition at line 312 of file StringObject.h.

References avmplus::MathUtils::convertStringToNumber(), getData(), getOffset(), length(), needsNormalization(), and normalize().

Referenced by avmplus::AvmCore::number(), and avmplus::AvmCore::numberAtom().

00313         {
00314             // For offset too since convertStringToNumber expects a null terminated string
00315             if (needsNormalization()) normalize();
00316             return MathUtils::convertStringToNumber(getData() + getOffset(), length());
00317         }

Stringp avmplus::String::toUpperCase  ) 
 

Returns a new string object which is a copy of this string object, with all characters in the string converted to uppercase.

Unicode character classes for uppercase and lowercase are used. The conversion behavior is compliant with the String.toUpperCase method.

Definition at line 760 of file StringObject.cpp.

References c_str(), MMgc::GC::GetGC(), length(), lockBuffer(), String(), unlockBuffer(), and wCharToUpper().

00761     {
00762         GC* gc = GC::GetGC(this);
00763         int len = length();
00764         Stringp out = new (gc) String(len);
00765 
00766         // Flag to detect whether any changes were made
00767         bool changed = false;
00768 
00769         // First, try quick conversion for low ASCII characters.
00770         wchar *dst = out->lockBuffer();
00771         const wchar *src = c_str();
00772         const wchar *end = src + len;
00773         wchar charIn, charOut;
00774         while (src < end) 
00775         {
00776             charIn = *src;
00777             if (charIn >= 0xFF)
00778                 break;
00779 
00780             charOut = String::toupper_map[charIn] ^ charIn;
00781             if (charOut != charIn) 
00782                 changed = true;
00783 
00784             *dst++ = charOut;
00785             src++;
00786         }
00787 
00788         // If that didn't work, resume from where we left off
00789         // with slow full Unicode conversion.
00790         while (src < end) 
00791         {
00792             charIn = *src;
00793             charOut = wCharToUpper(charIn);
00794             if (charOut != charIn)
00795                 changed = true;
00796 
00797             *dst++ = charOut;
00798             src++;  
00799         }
00800         
00801         *dst = 0;
00802         out->unlockBuffer();
00803 
00804         // Return new string.  If nothing changed, return old
00805         // string (the new string will be GC'd)
00806         return changed ? out : this;
00807     }

UTF8String * avmplus::String::toUTF8String  ) 
 

Converts this string to a UTF-8 string. Allocates a new UTF8 string object containing the result, and returns it.

Definition at line 316 of file StringObject.cpp.

References getData(), MMgc::GC::GetGC(), getOffset(), hasPrefix(), length(), avmplus::UTF8String::lockBuffer(), normalize(), NULL, avmplus::UTF8String::unlockBuffer(), and avmplus::UnicodeUtils::Utf16ToUtf8().

Referenced by avmplus::Toplevel::escapeBytes(), and avmplus::AvmCore::formatErrorMessageV().

00317     {
00318         if (hasPrefix()) normalize();
00319         int utf8len = UnicodeUtils::Utf16ToUtf8(getData() + getOffset(), length(), NULL, 0);
00320 
00321         if( utf8len < 0 )
00322         {
00323             utf8len = 0;
00324         }
00325 
00326         UTF8String* out = new (GC::GetGC(this), utf8len) UTF8String(utf8len);
00327         
00328         if (out) {
00329             char *dst = out->lockBuffer();
00330             UnicodeUtils::Utf16ToUtf8(getData() + getOffset(), length(), (uint8*)dst, utf8len);
00331             dst[utf8len] = 0;
00332             out->unlockBuffer();
00333         }
00334         return out;
00335     }

void avmplus::String::unlockBuffer  )  [inline]
 

Definition at line 184 of file StringObject.h.

00184 {}

void avmplus::String::unlockBuffer int  newLen  )  [inline]
 

Unlocks the buffer previously returned by lockBuffer. Must call after using lockBuffer to mutate the buffer.

Definition at line 179 of file StringObject.h.

References AvmAssert, isInterned(), and m_length.

Referenced by avmplus::XMLParser::condenseWhitespace(), toLowerCase(), toUpperCase(), and avmplus::Toplevel::unescape().

00180         {
00181             AvmAssert(!isInterned());
00182             m_length = newLen;
00183         }

wchar avmplus::String::wCharToLower wchar  ch  )  [static]
 

Definition at line 727 of file StringObject.cpp.

References AvmAssert, lowerCaseConversion, and upperCaseBase.

Referenced by toLowerCase().

00728     {
00729         AvmAssert (sizeof (upperCaseBase) == sizeof (lowerCaseConversion));
00730 
00731         wchar result = ch;
00732         // Do a binary search in upperCaseBase for wchar
00733         int lo = 0;
00734         int hi = (sizeof (upperCaseBase) / sizeof (upperCaseBase[0])) - 1;
00735 
00736         while (lo <= hi) 
00737         {
00738             int pivot = (lo+hi)>>1;
00739             int testChar = upperCaseBase[pivot];
00740 
00741             if (ch == testChar) 
00742             {
00743                 // Use that index into lowerCaseConversion for a return value
00744                 result =  lowerCaseConversion[pivot];
00745                 break;
00746             } 
00747             else if (ch < testChar) 
00748             {
00749                 hi = pivot-1;
00750             } 
00751             else 
00752             {
00753                 lo = pivot+1;
00754             }
00755         }
00756 
00757         return result;
00758     }

wchar avmplus::String::wCharToUpper wchar  ch  )  [static]
 

Definition at line 493 of file StringObject.cpp.

References AvmAssert, lowerCaseBase, and upperCaseConversion.

Referenced by toUpperCase().

00494     {
00495         AvmAssert (sizeof (lowerCaseBase) == sizeof (upperCaseConversion));
00496 
00497         wchar result = ch;
00498         // Do a binary search in lowerCaseBase for wchar
00499         int lo = 0;
00500         int hi = (sizeof (lowerCaseBase) / sizeof (lowerCaseBase[0])) - 1;
00501 
00502         while (lo <= hi) 
00503         {
00504             int pivot = (lo+hi)>>1;
00505             int testChar = lowerCaseBase[pivot];
00506 
00507             if (ch == testChar) 
00508             {
00509                 // Use that index into lowerCaseConversion for a return value
00510                 result =  upperCaseConversion[pivot];
00511                 break;
00512             } 
00513             else if (ch < testChar) 
00514             {
00515                 hi = pivot-1;
00516             } 
00517             else 
00518             {
00519                 lo = pivot+1;
00520             }
00521         }
00522 
00523         return result;
00524     }


Member Data Documentation

const wchar avmplus::String::lowerCaseBase [static, private]
 

Definition at line 405 of file StringObject.h.

Referenced by wCharToUpper().

const wchar avmplus::String::lowerCaseConversion [static, private]
 

Definition at line 407 of file StringObject.h.

Referenced by wCharToLower().

StringBuf* avmplus::String::m_buf [private]
 

Definition at line 361 of file StringObject.h.

Referenced by getData(), setBuf(), and String().

int avmplus::String::m_length [private]
 

Definition at line 348 of file StringObject.h.

Referenced by isInterned(), length(), setInterned(), unlockBuffer(), and ~String().

uintptr avmplus::String::m_prefixOrOffsetOrNumber [private]
 

Definition at line 369 of file StringObject.h.

Referenced by generateIntegerEquivalent(), getIntAtom(), getOffset(), getPrefix(), hasOffset(), hasPrefix(), needsNormalization(), and setPrefixOrOffsetOrNumber().

const unsigned char avmplus::String::tolower_map [static, private]
 

Initial value:

 {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 
        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 
        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  
    }

Definition at line 409 of file StringObject.h.

const unsigned char avmplus::String::toupper_map [static, private]
 

Initial value:

 {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 
        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 
        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 
        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20  
    }

Definition at line 410 of file StringObject.h.

const wchar avmplus::String::upperCaseBase [static, private]
 

Definition at line 406 of file StringObject.h.

Referenced by wCharToLower().

const wchar avmplus::String::upperCaseConversion [static, private]
 

Definition at line 408 of file StringObject.h.

Referenced by wCharToUpper().


The documentation for this class was generated from the following files:
Generated on Sun Oct 12 18:51:18 2008 for Tamarin by  doxygen 1.4.6