Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
dart::String Class Reference

#include <object.h>

Inheritance diagram for dart::String:
dart::Instance dart::Object

Classes

class  CodePointIterator
 

Public Member Functions

intptr_t Length () const
 
uword Hash () const
 
bool HasHash () const
 
virtual ObjectPtr HashCode () const
 
uint16_t CharAt (intptr_t index) const
 
intptr_t CharSize () const
 
bool Equals (const String &str) const
 
bool Equals (const String &str, intptr_t begin_index, intptr_t len) const
 
bool Equals (const char *cstr) const
 
bool EqualsLatin1 (const uint8_t *characters, intptr_t len) const
 
bool Equals (const uint16_t *characters, intptr_t len) const
 
bool Equals (const int32_t *characters, intptr_t len) const
 
bool EqualsConcat (const String &str1, const String &str2) const
 
virtual bool OperatorEquals (const Instance &other) const
 
virtual bool CanonicalizeEquals (const Instance &other) const
 
virtual uint32_t CanonicalizeHash () const
 
virtual bool Equals (const Instance &other) const
 
intptr_t CompareTo (const String &other) const
 
bool StartsWith (const String &other) const
 
bool EndsWith (const String &other) const
 
virtual InstancePtr CanonicalizeLocked (Thread *thread) const
 
bool IsSymbol () const
 
bool IsOneByteString () const
 
bool IsTwoByteString () const
 
char * ToMallocCString () const
 
void ToUTF8 (uint8_t *utf8_array, intptr_t array_len) const
 
- Public Member Functions inherited from dart::Instance
virtual bool OperatorEquals (const Instance &other) const
 
bool IsIdenticalTo (const Instance &other) const
 
virtual bool CanonicalizeEquals (const Instance &other) const
 
virtual uint32_t CanonicalizeHash () const
 
intptr_t SizeFromClass () const
 
InstancePtr Canonicalize (Thread *thread) const
 
virtual InstancePtr CanonicalizeLocked (Thread *thread) const
 
virtual void CanonicalizeFieldsLocked (Thread *thread) const
 
InstancePtr CopyShallowToOldSpace (Thread *thread) const
 
ObjectPtr GetField (const Field &field) const
 
void SetField (const Field &field, const Object &value) const
 
AbstractTypePtr GetType (Heap::Space space) const
 
virtual TypeArgumentsPtr GetTypeArguments () const
 
virtual void SetTypeArguments (const TypeArguments &value) const
 
bool IsInstanceOf (const AbstractType &other, const TypeArguments &other_instantiator_type_arguments, const TypeArguments &other_function_type_arguments) const
 
bool IsAssignableTo (const AbstractType &other, const TypeArguments &other_instantiator_type_arguments, const TypeArguments &other_function_type_arguments) const
 
bool IsValidNativeIndex (int index) const
 
intptr_t * NativeFieldsDataAddr () const
 
intptr_t GetNativeField (int index) const
 
void GetNativeFields (uint16_t num_fields, intptr_t *field_values) const
 
void SetNativeFields (uint16_t num_fields, const intptr_t *field_values) const
 
uint16_t NumNativeFields () const
 
void SetNativeField (int index, intptr_t value) const
 
bool IsCallable (Function *function) const
 
ObjectPtr Invoke (const String &selector, const Array &arguments, const Array &argument_names, bool respect_reflectable=true, bool check_is_entrypoint=false) const
 
ObjectPtr InvokeGetter (const String &selector, bool respect_reflectable=true, bool check_is_entrypoint=false) const
 
ObjectPtr InvokeSetter (const String &selector, const Instance &argument, bool respect_reflectable=true, bool check_is_entrypoint=false) const
 
ObjectPtr EvaluateCompiledExpression (const Class &klass, const ExternalTypedData &kernel_buffer, const Array &type_definitions, const Array &arguments, const TypeArguments &type_arguments) const
 
virtual ObjectPtr HashCode () const
 
IntegerPtr IdentityHashCode (Thread *thread) const
 
virtual bool IsPointer () const
 
- Public Member Functions inherited from dart::Object
virtual ~Object ()
 
ObjectPtr ptr () const
 
void operator= (ObjectPtr value)
 
bool IsCanonical () const
 
void SetCanonical () const
 
void ClearCanonical () const
 
bool IsImmutable () const
 
void SetImmutable () const
 
void ClearImmutable () const
 
intptr_t GetClassId () const
 
ClassPtr clazz () const
 
 CLASS_LIST_FOR_HANDLES (DEFINE_CLASS_TESTER)
 
bool IsNull () const
 
virtual const char * ToCString () const
 
void PrintJSON (JSONStream *stream, bool ref=true) const
 
virtual void PrintJSONImpl (JSONStream *stream, bool ref) const
 
void PrintImplementationFields (JSONStream *stream) const
 
virtual void PrintImplementationFieldsImpl (const JSONArray &jsarr_fields) const
 
virtual const char * JSONType () const
 
virtual StringPtr DictionaryName () const
 
bool IsNew () const
 
bool IsOld () const
 
bool InVMIsolateHeap () const
 
void Print () const
 

Static Public Member Functions

static intptr_t HeaderSize ()
 
static intptr_t InstanceSize ()
 
static intptr_t LengthOf (StringPtr obj)
 
static intptr_t length_offset ()
 
static uword Hash (StringPtr raw)
 
static intptr_t hash_offset ()
 
static uword Hash (const String &str, intptr_t begin_index, intptr_t len)
 
static uword Hash (const char *characters, intptr_t len)
 
static uword Hash (const uint16_t *characters, intptr_t len)
 
static uword Hash (const int32_t *characters, intptr_t len)
 
static uword HashRawSymbol (const StringPtr symbol)
 
static uword HashConcat (const String &str1, const String &str2)
 
static uint16_t CharAt (StringPtr str, intptr_t index)
 
static bool StartsWith (StringPtr str, StringPtr prefix)
 
static const char * ToCString (Thread *thread, StringPtr ptr)
 
static StringPtr New (const char *cstr, Heap::Space space=Heap::kNew)
 
static StringPtr FromUTF8 (const uint8_t *utf8_array, intptr_t array_len, Heap::Space space=Heap::kNew)
 
static StringPtr FromLatin1 (const uint8_t *latin1_array, intptr_t array_len, Heap::Space space=Heap::kNew)
 
static StringPtr FromUTF16 (const uint16_t *utf16_array, intptr_t array_len, Heap::Space space=Heap::kNew)
 
static StringPtr FromUTF32 (const int32_t *utf32_array, intptr_t array_len, Heap::Space space=Heap::kNew)
 
static StringPtr New (const String &str, Heap::Space space=Heap::kNew)
 
static StringPtr NewExternal (const uint8_t *utf8_array, intptr_t array_len, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback, Heap::Space=Heap::kNew)
 
static StringPtr NewExternal (const uint16_t *utf16_array, intptr_t array_len, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback, Heap::Space=Heap::kNew)
 
static void Copy (const String &dst, intptr_t dst_offset, const uint8_t *characters, intptr_t len)
 
static void Copy (const String &dst, intptr_t dst_offset, const uint16_t *characters, intptr_t len)
 
static void Copy (const String &dst, intptr_t dst_offset, const String &src, intptr_t src_offset, intptr_t len)
 
static StringPtr EscapeSpecialCharacters (const String &str)
 
static const char * EncodeIRI (const String &str)
 
static StringPtr DecodeIRI (const String &str)
 
static StringPtr Concat (const String &str1, const String &str2, Heap::Space space=Heap::kNew)
 
static StringPtr ConcatAll (const Array &strings, Heap::Space space=Heap::kNew)
 
static StringPtr ConcatAllRange (const Array &strings, intptr_t start, intptr_t end, Heap::Space space=Heap::kNew)
 
static StringPtr SubString (const String &str, intptr_t begin_index, Heap::Space space=Heap::kNew)
 
static StringPtr SubString (const String &str, intptr_t begin_index, intptr_t length, Heap::Space space=Heap::kNew)
 
static StringPtr SubString (Thread *thread, const String &str, intptr_t begin_index, intptr_t length, Heap::Space space=Heap::kNew)
 
static StringPtr Transform (int32_t(*mapping)(int32_t ch), const String &str, Heap::Space space=Heap::kNew)
 
static StringPtr ToUpperCase (const String &str, Heap::Space space=Heap::kNew)
 
static StringPtr ToLowerCase (const String &str, Heap::Space space=Heap::kNew)
 
static StringPtr RemovePrivateKey (const String &name)
 
static const char * ScrubName (const String &name, bool is_extension=false)
 
static StringPtr ScrubNameRetainPrivate (const String &name, bool is_extension=false)
 
static bool EqualsIgnoringPrivateKey (const String &str1, const String &str2)
 
static StringPtr NewFormatted (const char *format,...) PRINTF_ATTRIBUTE(1
 
static StringPtr static StringPtr NewFormatted (Heap::Space space, const char *format,...) PRINTF_ATTRIBUTE(2
 
static StringPtr static StringPtr static StringPtr NewFormattedV (const char *format, va_list args, Heap::Space space=Heap::kNew)
 
static bool ParseDouble (const String &str, intptr_t start, intptr_t end, double *result)
 
static uint32_t GetCachedHash (const StringPtr obj)
 
static uint32_t SetCachedHashIfNotSet (StringPtr obj, uint32_t hash)
 
static uint32_t SetCachedHash (StringPtr obj, uint32_t hash)
 
- Static Public Member Functions inherited from dart::Instance
static bool NullIsAssignableTo (const AbstractType &other)
 
static bool NullIsAssignableTo (const AbstractType &other, const TypeArguments &other_instantiator_type_arguments, const TypeArguments &other_function_type_arguments)
 
static ObjectPtr EvaluateCompiledExpression (Thread *thread, const Object &receiver, const Library &library, const Class &klass, const ExternalTypedData &kernel_buffer, const Array &type_definitions, const Array &param_values, const TypeArguments &type_param_values)
 
static intptr_t UnroundedSize ()
 
static intptr_t InstanceSize ()
 
static InstancePtr New (const Class &cls, Heap::Space space=Heap::kNew)
 
static InstancePtr NewAlreadyFinalized (const Class &cls, Heap::Space space=Heap::kNew)
 
static intptr_t DataOffsetFor (intptr_t cid)
 
static intptr_t ElementSizeFor (intptr_t cid)
 
static intptr_t NextFieldOffset ()
 
static intptr_t NativeFieldsOffset ()
 
- Static Public Member Functions inherited from dart::Object
static ObjectPtr RawCast (ObjectPtr obj)
 
static constexpr bool ContainsCompressedPointers ()
 
static intptr_t tags_offset ()
 
static ObjectHandle ()
 
static ObjectHandle (Zone *zone)
 
static ObjectHandle (ObjectPtr ptr)
 
static ObjectHandle (Zone *zone, ObjectPtr ptr)
 
static ObjectZoneHandle ()
 
static ObjectZoneHandle (Zone *zone)
 
static ObjectZoneHandle (ObjectPtr ptr)
 
static ObjectZoneHandle (Zone *zone, ObjectPtr ptr)
 
static ObjectReadOnlyHandle ()
 
static ObjectPtr null ()
 
static void set_vm_isolate_snapshot_object_table (const Array &table)
 
static ClassPtr class_class ()
 
static ClassPtr dynamic_class ()
 
static ClassPtr void_class ()
 
static ClassPtr type_parameters_class ()
 
static ClassPtr type_arguments_class ()
 
static ClassPtr patch_class_class ()
 
static ClassPtr function_class ()
 
static ClassPtr closure_data_class ()
 
static ClassPtr ffi_trampoline_data_class ()
 
static ClassPtr field_class ()
 
static ClassPtr script_class ()
 
static ClassPtr library_class ()
 
static ClassPtr namespace_class ()
 
static ClassPtr kernel_program_info_class ()
 
static ClassPtr code_class ()
 
static ClassPtr instructions_class ()
 
static ClassPtr instructions_section_class ()
 
static ClassPtr instructions_table_class ()
 
static ClassPtr object_pool_class ()
 
static ClassPtr pc_descriptors_class ()
 
static ClassPtr code_source_map_class ()
 
static ClassPtr compressed_stackmaps_class ()
 
static ClassPtr var_descriptors_class ()
 
static ClassPtr exception_handlers_class ()
 
static ClassPtr context_class ()
 
static ClassPtr context_scope_class ()
 
static ClassPtr sentinel_class ()
 
static ClassPtr api_error_class ()
 
static ClassPtr language_error_class ()
 
static ClassPtr unhandled_exception_class ()
 
static ClassPtr unwind_error_class ()
 
static ClassPtr singletargetcache_class ()
 
static ClassPtr unlinkedcall_class ()
 
static ClassPtr monomorphicsmiablecall_class ()
 
static ClassPtr icdata_class ()
 
static ClassPtr megamorphic_cache_class ()
 
static ClassPtr subtypetestcache_class ()
 
static ClassPtr loadingunit_class ()
 
static ClassPtr weak_serialization_reference_class ()
 
static ClassPtr weak_array_class ()
 
static void InitNullAndBool (IsolateGroup *isolate_group)
 
static void Init (IsolateGroup *isolate_group)
 
static void InitVtables ()
 
static void FinishInit (IsolateGroup *isolate_group)
 
static void FinalizeVMIsolate (IsolateGroup *isolate_group)
 
static void FinalizeReadOnlyObject (ObjectPtr object)
 
static void Cleanup ()
 
static ErrorPtr Init (IsolateGroup *isolate_group, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
 
static void MakeUnusedSpaceTraversable (const Object &obj, intptr_t original_size, intptr_t used_size)
 
static intptr_t InstanceSize ()
 
template<class FakeObject >
static void VerifyBuiltinVtable (intptr_t cid)
 
static void VerifyBuiltinVtables ()
 
static bool ShouldHaveImmutabilityBitSet (classid_t class_id)
 

Static Public Attributes

static constexpr intptr_t kOneByteChar = 1
 
static constexpr intptr_t kTwoByteChar = 2
 
static constexpr intptr_t kSizeofRawString
 
static constexpr intptr_t kMaxElements = kSmiMax / kTwoByteChar
 
- Static Public Attributes inherited from dart::Object
static constexpr intptr_t kHashBits = 30
 
static const ClassId kClassId = kObjectCid
 

Protected Member Functions

bool Equals (const uint8_t *characters, intptr_t len) const
 
void SetLength (intptr_t value) const
 
void SetHash (intptr_t value) const
 
 FINAL_HEAP_OBJECT_IMPLEMENTATION (String, Instance)
 
- Protected Member Functions inherited from dart::Instance
virtual void PrintSharedInstanceJSON (JSONObject *jsobj, bool ref, bool include_id=true) const
 
- Protected Member Functions inherited from dart::Object
 Object ()
 
uword raw_value () const
 
void setPtr (ObjectPtr value, intptr_t default_cid)
 
void CheckHandle () const
 
cpp_vtable vtable () const
 
void set_vtable (cpp_vtable value)
 
bool Contains (uword addr) const
 
template<typename type , std::memory_order order = std::memory_order_relaxed>
type LoadPointer (type const *addr) const
 
template<typename type , std::memory_order order = std::memory_order_relaxed>
void StorePointer (type const *addr, type value) const
 
template<typename type , typename compressed_type , std::memory_order order = std::memory_order_relaxed>
void StoreCompressedPointer (compressed_type const *addr, type value) const
 
template<typename type >
void StorePointerUnaligned (type const *addr, type value, Thread *thread) const
 
void StoreSmi (SmiPtr const *addr, SmiPtr value) const
 
template<typename FieldType >
void StoreSimd128 (const FieldType *addr, simd128_value_t value) const
 
template<typename FieldType >
FieldType LoadNonPointer (const FieldType *addr) const
 
template<typename FieldType , std::memory_order order>
FieldType LoadNonPointer (const FieldType *addr) const
 
template<typename FieldType , typename ValueType >
void StoreNonPointer (const FieldType *addr, ValueType value) const
 
template<typename FieldType , typename ValueType , std::memory_order order>
void StoreNonPointer (const FieldType *addr, ValueType value) const
 
template<typename FieldType >
FieldType * UnsafeMutableNonPointer (const FieldType *addr) const
 
 CLASS_LIST (STORE_NON_POINTER_ILLEGAL_TYPE)
 
void UnimplementedMethod () const
 
void AddCommonObjectProperties (JSONObject *jsobj, const char *protocol_type, bool ref) const
 

Static Protected Member Functions

static uword Hash (const uint8_t *characters, intptr_t len)
 
- Static Protected Member Functions inherited from dart::Object
static DART_NOINLINE ObjectHandleImpl (Zone *zone, ObjectPtr ptr, intptr_t default_cid)
 
static DART_NOINLINE ObjectZoneHandleImpl (Zone *zone, ObjectPtr ptr, intptr_t default_cid)
 
static DART_NOINLINE ObjectReadOnlyHandleImpl (intptr_t cid)
 
static ObjectPtr Allocate (intptr_t cls_id, intptr_t size, Heap::Space space, bool compressed, uword ptr_field_start_offset, uword ptr_field_end_offset)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType Allocate (Heap::Space space)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType Allocate (Heap::Space space, intptr_t elements)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType AllocateVariant (intptr_t class_id, Heap::Space space)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType AllocateVariant (intptr_t class_id, Heap::Space space, intptr_t elements)
 
static constexpr intptr_t RoundedAllocationSize (intptr_t size)
 
static ObjectPtr Clone (const Object &orig, Heap::Space space, bool load_with_relaxed_atomics=false)
 
template<typename T >
static DART_FORCE_INLINE uword from_offset ()
 
template<typename T >
static DART_FORCE_INLINE uword to_offset (intptr_t length=0)
 

Friends

class Class
 
class Symbols
 
class StringSlice
 
template<typename CharType >
class CharArray
 
class ConcatString
 
class OneByteString
 
class TwoByteString
 
class UntaggedOneByteString
 
class RODataSerializationCluster
 
class Pass2Visitor
 

Additional Inherited Members

- Public Types inherited from dart::Object
enum  NameVisibility { kInternalName = 0 , kScrubbedName , kUserVisibleName }
 
enum class  NameDisambiguation { kYes , kNo }
 
using UntaggedObjectType = UntaggedObject
 
using ObjectPtrType = ObjectPtr
 
- Protected Attributes inherited from dart::Object
ObjectPtr ptr_
 

Detailed Description

Definition at line 10158 of file object.h.

Member Function Documentation

◆ CanonicalizeEquals()

virtual bool dart::String::CanonicalizeEquals ( const Instance other) const
inlinevirtual

Reimplemented from dart::Instance.

Definition at line 10290 of file object.h.

10290 {
10291 return Equals(other);
10292 }
bool Equals(const String &str) const
Definition: object.h:13337

◆ CanonicalizeHash()

virtual uint32_t dart::String::CanonicalizeHash ( ) const
inlinevirtual

Reimplemented from dart::Instance.

Definition at line 10293 of file object.h.

10293{ return Hash(); }
uword Hash() const
Definition: object.h:10216

◆ CanonicalizeLocked()

InstancePtr dart::String::CanonicalizeLocked ( Thread thread) const
virtual

Reimplemented from dart::Instance.

Definition at line 23691 of file object.cc.

23691 {
23692 if (IsCanonical()) {
23693 return this->ptr();
23694 }
23695 return Symbols::New(Thread::Current(), *this);
23696}
ObjectPtr ptr() const
Definition: object.h:332
bool IsCanonical() const
Definition: object.h:335
static StringPtr New(Thread *thread, const char *cstr)
Definition: symbols.h:723
static Thread * Current()
Definition: thread.h:362

◆ CharAt() [1/2]

uint16_t dart::String::CharAt ( intptr_t  index) const
inline

Definition at line 10259 of file object.h.

10259{ return CharAt(ptr(), index); }
uint16_t CharAt(intptr_t index) const
Definition: object.h:10259

◆ CharAt() [2/2]

uint16_t dart::String::CharAt ( StringPtr  str,
intptr_t  index 
)
inlinestatic

Definition at line 13411 of file object.h.

13411 {
13412 switch (str->GetClassId()) {
13413 case kOneByteStringCid:
13414 return OneByteString::CharAt(static_cast<OneByteStringPtr>(str), index);
13415 case kTwoByteStringCid:
13416 return TwoByteString::CharAt(static_cast<TwoByteStringPtr>(str), index);
13417 }
13418 UNREACHABLE();
13419 return 0;
13420}
#define UNREACHABLE()
Definition: assert.h:248
static uint16_t CharAt(const String &str, intptr_t index)
Definition: object.h:10525
static uint16_t CharAt(const String &str, intptr_t index)
Definition: object.h:10664

◆ CharSize()

intptr_t dart::String::CharSize ( ) const

Definition at line 23522 of file object.cc.

23522 {
23523 intptr_t class_id = ptr()->GetClassId();
23524 if (class_id == kOneByteStringCid) {
23525 return kOneByteChar;
23526 }
23527 ASSERT(class_id == kTwoByteStringCid);
23528 return kTwoByteChar;
23529}
intptr_t GetClassId() const
Definition: raw_object.h:885
static constexpr intptr_t kOneByteChar
Definition: object.h:10160
static constexpr intptr_t kTwoByteChar
Definition: object.h:10161
#define ASSERT(E)

◆ CompareTo()

intptr_t dart::String::CompareTo ( const String other) const

Definition at line 23638 of file object.cc.

23638 {
23639 const intptr_t this_len = this->Length();
23640 const intptr_t other_len = other.IsNull() ? 0 : other.Length();
23641 const intptr_t len = (this_len < other_len) ? this_len : other_len;
23642 for (intptr_t i = 0; i < len; i++) {
23643 uint16_t this_code_unit = this->CharAt(i);
23644 uint16_t other_code_unit = other.CharAt(i);
23645 if (this_code_unit < other_code_unit) {
23646 return -1;
23647 }
23648 if (this_code_unit > other_code_unit) {
23649 return 1;
23650 }
23651 }
23652 if (this_len < other_len) return -1;
23653 if (this_len > other_len) return 1;
23654 return 0;
23655}
intptr_t Length() const
Definition: object.h:10210

◆ Concat()

StringPtr dart::String::Concat ( const String str1,
const String str2,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24037 of file object.cc.

24039 {
24040 ASSERT(!str1.IsNull() && !str2.IsNull());
24041 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize());
24042 if (char_size == kTwoByteChar) {
24043 return TwoByteString::Concat(str1, str2, space);
24044 }
24045 return OneByteString::Concat(str1, str2, space);
24046}
static OneByteStringPtr Concat(const String &str1, const String &str2, Heap::Space space)
Definition: object.cc:24461
static TwoByteStringPtr Concat(const String &str1, const String &str2, Heap::Space space)
Definition: object.cc:24640
static constexpr T Maximum(T x, T y)
Definition: utils.h:41

◆ ConcatAll()

StringPtr dart::String::ConcatAll ( const Array strings,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24048 of file object.cc.

24048 {
24049 return ConcatAllRange(strings, 0, strings.Length(), space);
24050}
static StringPtr ConcatAllRange(const Array &strings, intptr_t start, intptr_t end, Heap::Space space=Heap::kNew)
Definition: object.cc:24052

◆ ConcatAllRange()

StringPtr dart::String::ConcatAllRange ( const Array strings,
intptr_t  start,
intptr_t  end,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24052 of file object.cc.

24055 {
24056 ASSERT(!strings.IsNull());
24057 ASSERT(start >= 0);
24058 ASSERT(end <= strings.Length());
24059 intptr_t result_len = 0;
24060 String& str = String::Handle();
24061 intptr_t char_size = kOneByteChar;
24062 // Compute 'char_size' and 'result_len'.
24063 for (intptr_t i = start; i < end; i++) {
24064 str ^= strings.At(i);
24065 const intptr_t str_len = str.Length();
24066 if ((kMaxElements - result_len) < str_len) {
24068 UNREACHABLE();
24069 }
24070 result_len += str_len;
24071 char_size = Utils::Maximum(char_size, str.CharSize());
24072 }
24073 if (char_size == kOneByteChar) {
24074 return OneByteString::ConcatAll(strings, start, end, result_len, space);
24075 }
24076 ASSERT(char_size == kTwoByteChar);
24077 return TwoByteString::ConcatAll(strings, start, end, result_len, space);
24078}
static DART_NORETURN void ThrowOOM()
Definition: exceptions.cc:1066
static Object & Handle()
Definition: object.h:407
static OneByteStringPtr ConcatAll(const Array &strings, intptr_t start, intptr_t end, intptr_t len, Heap::Space space)
Definition: object.cc:24473
static constexpr intptr_t kMaxElements
Definition: object.h:10173
static TwoByteStringPtr ConcatAll(const Array &strings, intptr_t start, intptr_t end, intptr_t len, Heap::Space space)
Definition: object.cc:24652
glong glong end

◆ Copy() [1/3]

void dart::String::Copy ( const String dst,
intptr_t  dst_offset,
const String src,
intptr_t  src_offset,
intptr_t  len 
)
static

Definition at line 23834 of file object.cc.

23838 {
23839 ASSERT(dst_offset >= 0);
23840 ASSERT(src_offset >= 0);
23841 ASSERT(len >= 0);
23842 ASSERT(len <= (dst.Length() - dst_offset));
23843 ASSERT(len <= (src.Length() - src_offset));
23844 if (len > 0) {
23845 intptr_t char_size = src.CharSize();
23846 if (char_size == kOneByteChar) {
23847 ASSERT(src.IsOneByteString());
23848 NoSafepointScope no_safepoint;
23849 String::Copy(dst, dst_offset, OneByteString::CharAddr(src, src_offset),
23850 len);
23851 } else {
23852 ASSERT(char_size == kTwoByteChar);
23853 ASSERT(src.IsTwoByteString());
23854 NoSafepointScope no_safepoint;
23855 String::Copy(dst, dst_offset, TwoByteString::CharAddr(src, src_offset),
23856 len);
23857 }
23858 }
23859}
static void Copy(const String &dst, intptr_t dst_offset, const uint8_t *characters, intptr_t len)
Definition: object.cc:23792
dst
Definition: cp.py:12

◆ Copy() [2/3]

void dart::String::Copy ( const String dst,
intptr_t  dst_offset,
const uint16_t *  characters,
intptr_t  len 
)
static

Definition at line 23811 of file object.cc.

23814 {
23815 ASSERT(dst_offset >= 0);
23816 ASSERT(array_len >= 0);
23817 ASSERT(array_len <= (dst.Length() - dst_offset));
23818 if (dst.IsOneByteString()) {
23819 NoSafepointScope no_safepoint;
23820 for (intptr_t i = 0; i < array_len; ++i) {
23821 ASSERT(Utf::IsLatin1(LoadUnaligned(&utf16_array[i])));
23822 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i];
23823 }
23824 } else {
23825 ASSERT(dst.IsTwoByteString());
23826 NoSafepointScope no_safepoint;
23827 if (array_len > 0) {
23828 memmove(TwoByteString::CharAddr(dst, dst_offset), utf16_array,
23829 array_len * 2);
23830 }
23831 }
23832}
static bool IsLatin1(int32_t code_point)
Definition: unicode.h:23
static T LoadUnaligned(const T *ptr)
Definition: unaligned.h:14

◆ Copy() [3/3]

void dart::String::Copy ( const String dst,
intptr_t  dst_offset,
const uint8_t *  characters,
intptr_t  len 
)
static

Definition at line 23792 of file object.cc.

23795 {
23796 ASSERT(dst_offset >= 0);
23797 ASSERT(len >= 0);
23798 ASSERT(len <= (dst.Length() - dst_offset));
23799 if (dst.IsOneByteString()) {
23800 NoSafepointScope no_safepoint;
23801 if (len > 0) {
23802 memmove(OneByteString::CharAddr(dst, dst_offset), characters, len);
23803 }
23804 } else if (dst.IsTwoByteString()) {
23805 for (intptr_t i = 0; i < len; ++i) {
23806 *TwoByteString::CharAddr(dst, i + dst_offset) = characters[i];
23807 }
23808 }
23809}

◆ DecodeIRI()

StringPtr dart::String::DecodeIRI ( const String str)
static

Definition at line 23948 of file object.cc.

23948 {
23949 CodePointIterator cpi(str);
23950 intptr_t num_escapes = 0;
23951 intptr_t len = str.Length();
23952 {
23953 CodePointIterator cpi(str);
23954 while (cpi.Next()) {
23955 int32_t code_point = cpi.Current();
23956 if (IsPercent(code_point)) {
23957 // Verify that the two characters following the % are hex digits.
23958 if (!cpi.Next()) {
23959 return String::null();
23960 }
23961 int32_t code_point = cpi.Current();
23962 if (!IsHexCharacter(code_point)) {
23963 return String::null();
23964 }
23965 if (!cpi.Next()) {
23966 return String::null();
23967 }
23968 code_point = cpi.Current();
23969 if (!IsHexCharacter(code_point)) {
23970 return String::null();
23971 }
23972 num_escapes += 2;
23973 }
23974 }
23975 }
23976 intptr_t utf8_len = len - num_escapes;
23977 ASSERT(utf8_len >= 0);
23978 Zone* zone = Thread::Current()->zone();
23979 uint8_t* utf8 = zone->Alloc<uint8_t>(utf8_len);
23980 {
23981 intptr_t index = 0;
23982 CodePointIterator cpi(str);
23983 while (cpi.Next()) {
23984 ASSERT(index < utf8_len);
23985 int32_t code_point = cpi.Current();
23986 if (IsPercent(code_point)) {
23987 cpi.Next();
23988 int32_t ch1 = cpi.Current();
23989 cpi.Next();
23990 int32_t ch2 = cpi.Current();
23991 int32_t merged = MergeHexCharacters(ch1, ch2);
23992 ASSERT(merged >= 0 && merged < 256);
23993 utf8[index] = static_cast<uint8_t>(merged);
23994 } else {
23995 ASSERT(code_point >= 0 && code_point < 256);
23996 utf8[index] = static_cast<uint8_t>(code_point);
23997 }
23998 index++;
23999 }
24000 }
24001 return FromUTF8(utf8, utf8_len);
24002}
static ObjectPtr null()
Definition: object.h:433
static StringPtr FromUTF8(const uint8_t *utf8_array, intptr_t array_len, Heap::Space space=Heap::kNew)
Definition: object.cc:23705
Zone * zone() const
Definition: thread_state.h:37
static bool IsPercent(int32_t c)
Definition: object.cc:23869
static bool IsHexCharacter(int32_t c)
Definition: object.cc:23873
static int32_t MergeHexCharacters(int32_t c1, int32_t c2)
Definition: object.cc:23914

◆ EncodeIRI()

const char * dart::String::EncodeIRI ( const String str)
static

Definition at line 23918 of file object.cc.

23918 {
23919 const intptr_t len = Utf8::Length(str);
23920 Zone* zone = Thread::Current()->zone();
23921 uint8_t* utf8 = zone->Alloc<uint8_t>(len);
23922 str.ToUTF8(utf8, len);
23923 intptr_t num_escapes = 0;
23924 for (int i = 0; i < len; ++i) {
23925 uint8_t byte = utf8[i];
23926 if (!IsURISafeCharacter(byte)) {
23927 num_escapes += 2;
23928 }
23929 }
23930 intptr_t cstr_len = len + num_escapes + 1;
23931 char* cstr = zone->Alloc<char>(cstr_len);
23932 intptr_t index = 0;
23933 for (int i = 0; i < len; ++i) {
23934 uint8_t byte = utf8[i];
23935 if (!IsURISafeCharacter(byte)) {
23936 cstr[index++] = '%';
23937 cstr[index++] = GetHexCharacter(byte >> 4);
23938 cstr[index++] = GetHexCharacter(byte & 0xF);
23939 } else {
23940 ASSERT(byte <= 127);
23941 cstr[index++] = byte;
23942 }
23943 }
23944 cstr[index] = '\0';
23945 return cstr;
23946}
static intptr_t Length(int32_t ch)
Definition: unicode.cc:98
static int32_t GetHexCharacter(int32_t c)
Definition: object.cc:23896
static bool IsURISafeCharacter(int32_t c)
Definition: object.cc:23883

◆ EndsWith()

bool dart::String::EndsWith ( const String other) const

Definition at line 23672 of file object.cc.

23672 {
23673 if (other.IsNull()) {
23674 return false;
23675 }
23676 const intptr_t len = this->Length();
23677 const intptr_t other_len = other.Length();
23678 const intptr_t offset = len - other_len;
23679
23680 if ((other_len == 0) || (other_len > len)) {
23681 return false;
23682 }
23683 for (int i = offset; i < len; i++) {
23684 if (this->CharAt(i) != other.CharAt(i - offset)) {
23685 return false;
23686 }
23687 }
23688 return true;
23689}
SeparatedVector2 offset

◆ Equals() [1/7]

bool dart::String::Equals ( const char *  cstr) const

Definition at line 23565 of file object.cc.

23565 {
23566 ASSERT(cstr != nullptr);
23567 CodePointIterator it(*this);
23568 intptr_t len = strlen(cstr);
23569 while (it.Next()) {
23570 if (*cstr == '\0') {
23571 // Lengths don't match.
23572 return false;
23573 }
23574 int32_t ch;
23575 intptr_t consumed =
23576 Utf8::Decode(reinterpret_cast<const uint8_t*>(cstr), len, &ch);
23577 if (consumed == 0 || it.Current() != ch) {
23578 return false;
23579 }
23580 cstr += consumed;
23581 len -= consumed;
23582 }
23583 return *cstr == '\0';
23584}
static intptr_t Decode(const uint8_t *utf8_array, intptr_t array_len, int32_t *ch)
Definition: unicode.cc:135

◆ Equals() [2/7]

bool dart::String::Equals ( const Instance other) const
virtual

Definition at line 23531 of file object.cc.

23531 {
23532 if (this->ptr() == other.ptr()) {
23533 // Both handles point to the same raw instance.
23534 return true;
23535 }
23536
23537 if (!other.IsString()) {
23538 return false;
23539 }
23540
23541 const String& other_string = String::Cast(other);
23542 return Equals(other_string);
23543}

◆ Equals() [3/7]

bool dart::String::Equals ( const int32_t *  characters,
intptr_t  len 
) const

Definition at line 23614 of file object.cc.

23614 {
23615 if (len < 0) return false;
23616 intptr_t j = 0;
23617 for (intptr_t i = 0; i < len; ++i) {
23618 if (Utf::IsSupplementary(utf32_array[i])) {
23619 uint16_t encoded[2];
23620 Utf16::Encode(utf32_array[i], &encoded[0]);
23621 if (j + 1 >= Length()) return false;
23622 if (CharAt(j++) != encoded[0]) return false;
23623 if (CharAt(j++) != encoded[1]) return false;
23624 } else {
23625 if (j >= Length()) return false;
23626 if (CharAt(j++) != utf32_array[i]) return false;
23627 }
23628 }
23629 return j == Length();
23630}
static void Encode(int32_t codepoint, uint16_t *dst)
Definition: unicode.cc:273
static bool IsSupplementary(int32_t code_point)
Definition: unicode.h:31

◆ Equals() [4/7]

bool dart::String::Equals ( const String str) const
inline

Definition at line 13337 of file object.h.

13337 {
13338 if (ptr() == str.ptr()) {
13339 return true; // Both handles point to the same raw instance.
13340 }
13341 if (str.IsNull()) {
13342 return false;
13343 }
13344 if (IsCanonical() && str.IsCanonical()) {
13345 return false; // Two symbols that aren't identical aren't equal.
13346 }
13347 if (HasHash() && str.HasHash() && (Hash() != str.Hash())) {
13348 return false; // Both sides have hash codes and they do not match.
13349 }
13350 return Equals(str, 0, str.Length());
13351}
bool HasHash() const
Definition: object.h:10229

◆ Equals() [5/7]

bool dart::String::Equals ( const String str,
intptr_t  begin_index,
intptr_t  len 
) const

Definition at line 23545 of file object.cc.

23547 {
23548 ASSERT(begin_index >= 0);
23549 ASSERT((begin_index == 0) || (begin_index < str.Length()));
23550 ASSERT(len >= 0);
23551 ASSERT(len <= str.Length());
23552 if (len != this->Length()) {
23553 return false; // Lengths don't match.
23554 }
23555
23556 for (intptr_t i = 0; i < len; i++) {
23557 if (CharAt(i) != str.CharAt(begin_index + i)) {
23558 return false;
23559 }
23560 }
23561
23562 return true;
23563}

◆ Equals() [6/7]

bool dart::String::Equals ( const uint16_t *  characters,
intptr_t  len 
) const

Definition at line 23600 of file object.cc.

23600 {
23601 if (len != this->Length()) {
23602 // Lengths don't match.
23603 return false;
23604 }
23605
23606 for (intptr_t i = 0; i < len; i++) {
23607 if (this->CharAt(i) != LoadUnaligned(&utf16_array[i])) {
23608 return false;
23609 }
23610 }
23611 return true;
23612}

◆ Equals() [7/7]

bool dart::String::Equals ( const uint8_t *  characters,
intptr_t  len 
) const
protected

Definition at line 23586 of file object.cc.

23586 {
23587 if (len != this->Length()) {
23588 // Lengths don't match.
23589 return false;
23590 }
23591
23592 for (intptr_t i = 0; i < len; i++) {
23593 if (this->CharAt(i) != latin1_array[i]) {
23594 return false;
23595 }
23596 }
23597 return true;
23598}

◆ EqualsConcat()

bool dart::String::EqualsConcat ( const String str1,
const String str2 
) const

Definition at line 23632 of file object.cc.

23632 {
23633 return (Length() == str1.Length() + str2.Length()) &&
23634 str1.Equals(*this, 0, str1.Length()) &&
23635 str2.Equals(*this, str1.Length(), str2.Length());
23636}

◆ EqualsIgnoringPrivateKey()

bool dart::String::EqualsIgnoringPrivateKey ( const String str1,
const String str2 
)
static

Definition at line 24299 of file object.cc.

24299 {
24300 if (str1.ptr() == str2.ptr()) {
24301 return true; // Both handles point to the same raw instance.
24302 }
24303 NoSafepointScope no_safepoint;
24304 intptr_t str1_class_id = str1.ptr()->GetClassId();
24305 intptr_t str2_class_id = str2.ptr()->GetClassId();
24306 switch (str1_class_id) {
24307 case kOneByteStringCid:
24308 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, OneByteString, str1, str2);
24309 break;
24310 case kTwoByteStringCid:
24311 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, TwoByteString, str1, str2);
24312 break;
24313 }
24314 UNREACHABLE();
24315 return false;
24316}
friend class TwoByteString
Definition: object.h:10491
friend class OneByteString
Definition: object.h:10490
#define EQUALS_IGNORING_PRIVATE_KEY(class_id, type, str1, str2)
Definition: object.cc:24290

◆ EqualsLatin1()

bool dart::String::EqualsLatin1 ( const uint8_t *  characters,
intptr_t  len 
) const
inline

Definition at line 10274 of file object.h.

10274 {
10275 return Equals(characters, len);
10276 }

◆ EscapeSpecialCharacters()

StringPtr dart::String::EscapeSpecialCharacters ( const String str)
static

Definition at line 23861 of file object.cc.

23861 {
23862 if (str.IsOneByteString()) {
23864 }
23865 ASSERT(str.IsTwoByteString());
23867}
static OneByteStringPtr EscapeSpecialCharacters(const String &str)
Definition: object.cc:24336
static TwoByteStringPtr EscapeSpecialCharacters(const String &str)
Definition: object.cc:24530

◆ FINAL_HEAP_OBJECT_IMPLEMENTATION()

dart::String::FINAL_HEAP_OBJECT_IMPLEMENTATION ( String  ,
Instance   
)
protected

◆ FromLatin1()

StringPtr dart::String::FromLatin1 ( const uint8_t *  latin1_array,
intptr_t  array_len,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 23733 of file object.cc.

23735 {
23736 return OneByteString::New(latin1_array, array_len, space);
23737}
static OneByteStringPtr New(intptr_t len, Heap::Space space)
Definition: object.cc:24368

◆ FromUTF16()

StringPtr dart::String::FromUTF16 ( const uint16_t *  utf16_array,
intptr_t  array_len,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 23739 of file object.cc.

23741 {
23742 bool is_one_byte_string = true;
23743 for (intptr_t i = 0; i < array_len; ++i) {
23744 if (!Utf::IsLatin1(LoadUnaligned(&utf16_array[i]))) {
23745 is_one_byte_string = false;
23746 break;
23747 }
23748 }
23749 if (is_one_byte_string) {
23750 return OneByteString::New(utf16_array, array_len, space);
23751 }
23752 return TwoByteString::New(utf16_array, array_len, space);
23753}
static TwoByteStringPtr New(intptr_t len, Heap::Space space)
Definition: object.cc:24562

◆ FromUTF32()

StringPtr dart::String::FromUTF32 ( const int32_t *  utf32_array,
intptr_t  array_len,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 23755 of file object.cc.

23757 {
23758 bool is_one_byte_string = true;
23759 intptr_t utf16_len = array_len;
23760 for (intptr_t i = 0; i < array_len; ++i) {
23761 if (!Utf::IsLatin1(utf32_array[i])) {
23762 is_one_byte_string = false;
23763 if (Utf::IsSupplementary(utf32_array[i])) {
23764 utf16_len += 1;
23765 }
23766 }
23767 }
23768 if (is_one_byte_string) {
23769 return OneByteString::New(utf32_array, array_len, space);
23770 }
23771 return TwoByteString::New(utf16_len, utf32_array, array_len, space);
23772}

◆ FromUTF8()

StringPtr dart::String::FromUTF8 ( const uint8_t *  utf8_array,
intptr_t  array_len,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 23705 of file object.cc.

23707 {
23709 intptr_t len = Utf8::CodeUnitCount(utf8_array, array_len, &type);
23710 if (type == Utf8::kLatin1) {
23711 const String& strobj = String::Handle(OneByteString::New(len, space));
23712 if (len > 0) {
23713 NoSafepointScope no_safepoint;
23714 if (!Utf8::DecodeToLatin1(utf8_array, array_len,
23715 OneByteString::DataStart(strobj), len)) {
23716 Utf8::ReportInvalidByte(utf8_array, array_len, len);
23717 return String::null();
23718 }
23719 }
23720 return strobj.ptr();
23721 }
23723 const String& strobj = String::Handle(TwoByteString::New(len, space));
23724 NoSafepointScope no_safepoint;
23725 if (!Utf8::DecodeToUTF16(utf8_array, array_len,
23726 TwoByteString::DataStart(strobj), len)) {
23727 Utf8::ReportInvalidByte(utf8_array, array_len, len);
23728 return String::null();
23729 }
23730 return strobj.ptr();
23731}
GLenum type
@ kSupplementary
Definition: unicode.h:46
@ kLatin1
Definition: unicode.h:44
static intptr_t CodeUnitCount(const uint8_t *utf8_array, intptr_t array_len, Type *type)
Definition: unicode.cc:46
static intptr_t ReportInvalidByte(const uint8_t *utf8_array, intptr_t array_len, intptr_t len)
Definition: unicode.cc:163
static bool DecodeToUTF16(const uint8_t *utf8_array, intptr_t array_len, uint16_t *dst, intptr_t len)
Definition: unicode.cc:217
static bool DecodeToLatin1(const uint8_t *utf8_array, intptr_t array_len, uint8_t *dst, intptr_t len)
Definition: unicode.cc:194

◆ GetCachedHash()

static uint32_t dart::String::GetCachedHash ( const StringPtr  obj)
inlinestatic

Definition at line 10445 of file object.h.

10445 {
10446 return Smi::Value(obj->untag()->hash_);
10447 }
intptr_t Value() const
Definition: object.h:9990

◆ Hash() [1/7]

uword dart::String::Hash ( ) const
inline

Definition at line 10216 of file object.h.

10216 {
10218 if (result != 0) {
10219 return result;
10220 }
10221 result = String::Hash(*this, 0, this->Length());
10222 uword set_hash = SetCachedHashIfNotSet(ptr(), result);
10223 ASSERT(set_hash == result);
10224 return result;
10225 }
static uint32_t SetCachedHashIfNotSet(StringPtr obj, uint32_t hash)
Definition: object.h:10449
static uint32_t GetCachedHash(const StringPtr obj)
Definition: object.h:10445
GAsyncResult * result
uintptr_t uword
Definition: globals.h:501

◆ Hash() [2/7]

uword dart::String::Hash ( const char *  characters,
intptr_t  len 
)
static

Definition at line 23504 of file object.cc.

23504 {
23505 StringHasher hasher;
23506 hasher.Add(reinterpret_cast<const uint8_t*>(characters), len);
23507 return hasher.Finalize();
23508}

◆ Hash() [3/7]

static uword dart::String::Hash ( const int32_t *  characters,
intptr_t  len 
)
static

◆ Hash() [4/7]

uword dart::String::Hash ( const String str,
intptr_t  begin_index,
intptr_t  len 
)
static

Definition at line 23479 of file object.cc.

23479 {
23480 StringHasher hasher;
23481 hasher.Add(str, begin_index, len);
23482 return hasher.Finalize();
23483}

◆ Hash() [5/7]

uword dart::String::Hash ( const uint16_t *  characters,
intptr_t  len 
)
static

Definition at line 23516 of file object.cc.

23516 {
23517 StringHasher hasher;
23518 hasher.Add(characters, len);
23519 return hasher.Finalize();
23520}

◆ Hash() [6/7]

uword dart::String::Hash ( const uint8_t *  characters,
intptr_t  len 
)
staticprotected

Definition at line 23510 of file object.cc.

23510 {
23511 StringHasher hasher;
23512 hasher.Add(characters, len);
23513 return hasher.Finalize();
23514}

◆ Hash() [7/7]

uword dart::String::Hash ( StringPtr  raw)
static

Definition at line 23492 of file object.cc.

23492 {
23493 StringHasher hasher;
23494 uword length = Smi::Value(raw->untag()->length());
23495 if (raw->IsOneByteString()) {
23496 const uint8_t* data = static_cast<OneByteStringPtr>(raw)->untag()->data();
23497 return String::Hash(data, length);
23498 } else {
23499 const uint16_t* data = static_cast<TwoByteStringPtr>(raw)->untag()->data();
23500 return String::Hash(data, length);
23501 }
23502}
size_t length
raw_obj untag() -> num_entries()) VARIABLE_COMPRESSED_VISITOR(Array, Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(TypedData, TypedData::ElementSizeInBytes(raw_obj->GetClassId()) *Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(Record, RecordShape(raw_obj->untag() ->shape()).num_fields()) VARIABLE_NULL_VISITOR(CompressedStackMaps, CompressedStackMaps::PayloadSizeOf(raw_obj)) VARIABLE_NULL_VISITOR(OneByteString, Smi::Value(raw_obj->untag() ->length())) VARIABLE_NULL_VISITOR(TwoByteString, Smi::Value(raw_obj->untag() ->length())) intptr_t UntaggedField::VisitFieldPointers(FieldPtr raw_obj, ObjectPointerVisitor *visitor)
Definition: raw_object.cc:558
static int8_t data[kExtLength]

◆ hash_offset()

static intptr_t dart::String::hash_offset ( )
inlinestatic

Definition at line 10234 of file object.h.

10234 {
10235#if defined(HASH_IN_OBJECT_HEADER)
10237 return OFFSET_OF(UntaggedObject, tags_) +
10239#else
10240 return OFFSET_OF(UntaggedString, hash_);
10241#endif
10242 }
constexpr intptr_t kBitsPerByte
Definition: globals.h:463
COMPILE_ASSERT(kUnreachableReference==WeakTable::kNoValue)
#define OFFSET_OF(type, field)
Definition: globals.h:138

◆ HasHash()

bool dart::String::HasHash ( ) const
inline

Definition at line 10229 of file object.h.

10229 {
10230 ASSERT(Smi::New(0) == nullptr);
10231 return GetCachedHash(ptr()) != 0;
10232 }
static SmiPtr New(intptr_t value)
Definition: object.h:10006

◆ HashCode()

virtual ObjectPtr dart::String::HashCode ( ) const
inlinevirtual

Reimplemented from dart::Instance.

Definition at line 10257 of file object.h.

10257{ return Integer::New(Hash()); }
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition: object.cc:22984

◆ HashConcat()

uword dart::String::HashConcat ( const String str1,
const String str2 
)
static

Definition at line 23485 of file object.cc.

23485 {
23486 StringHasher hasher;
23487 hasher.Add(str1, 0, str1.Length());
23488 hasher.Add(str2, 0, str2.Length());
23489 return hasher.Finalize();
23490}

◆ HashRawSymbol()

static uword dart::String::HashRawSymbol ( const StringPtr  symbol)
inlinestatic

Definition at line 10247 of file object.h.

10247 {
10248 ASSERT(symbol->untag()->IsCanonical());
10249 const uword result = GetCachedHash(symbol);
10250 ASSERT(result != 0);
10251 return result;
10252 }

◆ HeaderSize()

static intptr_t dart::String::HeaderSize ( )
inlinestatic

Definition at line 10175 of file object.h.

10175{ return String::kSizeofRawString; }
static constexpr intptr_t kSizeofRawString
Definition: object.h:10170

◆ InstanceSize()

static intptr_t dart::String::InstanceSize ( )
inlinestatic

Definition at line 10177 of file object.h.

10177 {
10178 return RoundedAllocationSize(sizeof(UntaggedString));
10179 }
static constexpr intptr_t RoundedAllocationSize(intptr_t size)
Definition: object.h:758

◆ IsOneByteString()

bool dart::String::IsOneByteString ( ) const
inline

Definition at line 10311 of file object.h.

10311 {
10312 return ptr()->GetClassId() == kOneByteStringCid;
10313 }

◆ IsSymbol()

bool dart::String::IsSymbol ( ) const
inline

Definition at line 10309 of file object.h.

10309{ return ptr()->untag()->IsCanonical(); }
UntaggedObject * untag() const
bool IsCanonical() const
Definition: raw_object.h:350

◆ IsTwoByteString()

bool dart::String::IsTwoByteString ( ) const
inline

Definition at line 10315 of file object.h.

10315 {
10316 return ptr()->GetClassId() == kTwoByteStringCid;
10317 }

◆ Length()

intptr_t dart::String::Length ( ) const
inline

Definition at line 10210 of file object.h.

10210{ return LengthOf(ptr()); }
static intptr_t LengthOf(StringPtr obj)
Definition: object.h:10211

◆ length_offset()

static intptr_t dart::String::length_offset ( )
inlinestatic

Definition at line 10214 of file object.h.

10214{ return OFFSET_OF(UntaggedString, length_); }

◆ LengthOf()

static intptr_t dart::String::LengthOf ( StringPtr  obj)
inlinestatic

Definition at line 10211 of file object.h.

10211 {
10212 return Smi::Value(obj->untag()->length());
10213 }

◆ New() [1/2]

StringPtr dart::String::New ( const char *  cstr,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 23698 of file object.cc.

23698 {
23699 ASSERT(cstr != nullptr);
23700 intptr_t array_len = strlen(cstr);
23701 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(cstr);
23702 return String::FromUTF8(utf8_array, array_len, space);
23703}

◆ New() [2/2]

StringPtr dart::String::New ( const String str,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 23774 of file object.cc.

23774 {
23775 // Currently this just creates a copy of the string in the correct space.
23776 // Once we have external string support, this will also create a heap copy of
23777 // the string if necessary. Some optimizations are possible, such as not
23778 // copying internal strings into the same space.
23779 intptr_t len = str.Length();
23780 String& result = String::Handle();
23781 intptr_t char_size = str.CharSize();
23782 if (char_size == kOneByteChar) {
23783 result = OneByteString::New(len, space);
23784 } else {
23785 ASSERT(char_size == kTwoByteChar);
23786 result = TwoByteString::New(len, space);
23787 }
23788 String::Copy(result, 0, str, 0, len);
23789 return result.ptr();
23790}

◆ NewExternal() [1/2]

static StringPtr dart::String::NewExternal ( const uint16_t *  utf16_array,
intptr_t  array_len,
void *  peer,
intptr_t  external_allocation_size,
Dart_HandleFinalizer  callback,
Heap::Space  = Heap::kNew 
)
static

◆ NewExternal() [2/2]

static StringPtr dart::String::NewExternal ( const uint8_t *  utf8_array,
intptr_t  array_len,
void *  peer,
intptr_t  external_allocation_size,
Dart_HandleFinalizer  callback,
Heap::Space  = Heap::kNew 
)
static

◆ NewFormatted() [1/2]

StringPtr dart::String::NewFormatted ( const char *  format,
  ... 
)
static

Definition at line 24004 of file object.cc.

24004 {
24005 va_list args;
24007 StringPtr result = NewFormattedV(format, args);
24008 NoSafepointScope no_safepoint;
24009 va_end(args);
24010 return result;
24011}
static StringPtr static StringPtr static StringPtr NewFormattedV(const char *format, va_list args, Heap::Space space=Heap::kNew)
Definition: object.cc:24022
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
va_start(args, format)
va_end(args)

◆ NewFormatted() [2/2]

StringPtr dart::String::NewFormatted ( Heap::Space  space,
const char *  format,
  ... 
)
static

Definition at line 24013 of file object.cc.

24013 {
24014 va_list args;
24016 StringPtr result = NewFormattedV(format, args, space);
24017 NoSafepointScope no_safepoint;
24018 va_end(args);
24019 return result;
24020}

◆ NewFormattedV()

StringPtr dart::String::NewFormattedV ( const char *  format,
va_list  args,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24022 of file object.cc.

24024 {
24025 va_list args_copy;
24026 va_copy(args_copy, args);
24027 intptr_t len = Utils::VSNPrint(nullptr, 0, format, args_copy);
24028 va_end(args_copy);
24029
24030 Zone* zone = Thread::Current()->zone();
24031 char* buffer = zone->Alloc<char>(len + 1);
24033
24034 return String::New(buffer, space);
24035}
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ OperatorEquals()

virtual bool dart::String::OperatorEquals ( const Instance other) const
inlinevirtual

Reimplemented from dart::Instance.

Definition at line 10287 of file object.h.

10287 {
10288 return Equals(other);
10289 }

◆ ParseDouble()

bool dart::String::ParseDouble ( const String str,
intptr_t  start,
intptr_t  end,
double *  result 
)
static

Definition at line 24207 of file object.cc.

24210 {
24211 ASSERT(0 <= start);
24212 ASSERT(start <= end);
24213 ASSERT(end <= str.Length());
24214 intptr_t length = end - start;
24215 NoSafepointScope no_safepoint;
24216 const uint8_t* startChar;
24217 if (str.IsOneByteString()) {
24218 startChar = OneByteString::CharAddr(str, start);
24219 } else {
24220 uint8_t* chars = Thread::Current()->zone()->Alloc<uint8_t>(length);
24221 for (intptr_t i = 0; i < length; i++) {
24222 int32_t ch = str.CharAt(start + i);
24223 if (ch < 128) {
24224 chars[i] = ch;
24225 } else {
24226 return false; // Not ASCII, so definitely not valid double numeral.
24227 }
24228 }
24229 startChar = chars;
24230 }
24231 return CStringToDouble(reinterpret_cast<const char*>(startChar), length,
24232 result);
24233}
ElementType * Alloc(intptr_t length)
bool CStringToDouble(const char *str, intptr_t length, double *result)

◆ RemovePrivateKey()

StringPtr dart::String::RemovePrivateKey ( const String name)
static

Definition at line 233 of file object.cc.

233 {
234 ASSERT(name.IsOneByteString());
235 GrowableArray<uint8_t> without_key(name.Length());
236 intptr_t i = 0;
237 while (i < name.Length()) {
238 while (i < name.Length()) {
239 uint8_t c = name.CharAt(i++);
240 if (c == '@') break;
241 without_key.Add(c);
242 }
243 while (i < name.Length()) {
244 uint8_t c = name.CharAt(i);
245 if ((c < '0') || (c > '9')) break;
246 i++;
247 }
248 }
249
250 return String::FromLatin1(without_key.data(), without_key.length());
251}
static StringPtr FromLatin1(const uint8_t *latin1_array, intptr_t array_len, Heap::Space space=Heap::kNew)
Definition: object.cc:23733
const char *const name

◆ ScrubName()

const char * dart::String::ScrubName ( const String name,
bool  is_extension = false 
)
static

Definition at line 287 of file object.cc.

287 {
288 Thread* thread = Thread::Current();
289 NoSafepointScope no_safepoint(thread);
290 Zone* zone = thread->zone();
291 ZoneTextBuffer printer(zone);
292
293#if !defined(DART_PRECOMPILED_RUNTIME)
294 if (name.Equals(Symbols::TopLevel())) {
295 // Name of invisible top-level class.
296 return "";
297 }
298#endif // !defined(DART_PRECOMPILED_RUNTIME)
299
300 const char* cname = name.ToCString();
301 ASSERT(strlen(cname) == static_cast<size_t>(name.Length()));
302 const intptr_t name_len = name.Length();
303 // First remove all private name mangling and if 'is_extension' is true
304 // substitute the first '|' character with '.'.
305 intptr_t start_pos = 0;
306 intptr_t sum_segment_len = 0;
307 for (intptr_t i = 0; i < name_len; i++) {
308 if ((cname[i] == '@') && ((i + 1) < name_len) && (cname[i + 1] >= '0') &&
309 (cname[i + 1] <= '9')) {
310 // Append the current segment to the unmangled name.
311 const intptr_t segment_len = i - start_pos;
312 sum_segment_len += segment_len;
313 AppendSubString(&printer, cname, start_pos, segment_len);
314 // Advance until past the name mangling. The private keys are only
315 // numbers so we skip until the first non-number.
316 i++; // Skip the '@'.
317 while ((i < name.Length()) && (name.CharAt(i) >= '0') &&
318 (name.CharAt(i) <= '9')) {
319 i++;
320 }
321 start_pos = i;
322 i--; // Account for for-loop increment.
323 } else if (is_extension && cname[i] == '|') {
324 // Append the current segment to the unmangled name.
325 const intptr_t segment_len = i - start_pos;
326 AppendSubString(&printer, cname, start_pos, segment_len);
327 // Append the '.' character (replaces '|' with '.').
328 AppendSubString(&printer, ".", 0, 1);
329 start_pos = i + 1;
330 // Account for length of segments added so far.
331 sum_segment_len += (segment_len + 1);
332 }
333 }
334
335 const char* unmangled_name = nullptr;
336 if (start_pos == 0) {
337 // No name unmangling needed, reuse the name that was passed in.
338 unmangled_name = cname;
339 sum_segment_len = name_len;
340 } else if (name.Length() != start_pos) {
341 // Append the last segment.
342 const intptr_t segment_len = name.Length() - start_pos;
343 sum_segment_len += segment_len;
344 AppendSubString(&printer, cname, start_pos, segment_len);
345 }
346 if (unmangled_name == nullptr) {
347 // Merge unmangled_segments.
348 unmangled_name = printer.buffer();
349 }
350
351 printer.Clear();
352 intptr_t start = 0;
353 intptr_t len = sum_segment_len;
354 bool is_setter = false;
355 if (is_extension) {
356 // First scan till we see the '.' character.
357 for (intptr_t i = 0; i < len; i++) {
358 if (unmangled_name[i] == '.') {
359 intptr_t slen = i + 1;
360 intptr_t plen = slen - start;
361 AppendSubString(&printer, unmangled_name, start, plen);
362 unmangled_name += slen;
363 len -= slen;
364 break;
365 } else if (unmangled_name[i] == ':') {
366 if (start != 0) {
367 // Reset and break.
368 start = 0;
369 is_setter = false;
370 break;
371 }
372 if (unmangled_name[0] == 's') {
373 is_setter = true;
374 }
375 start = i + 1;
376 }
377 }
378 }
379 intptr_t dot_pos = -1; // Position of '.' in the name, if any.
380 start = 0;
381 for (intptr_t i = start; i < len; i++) {
382 if (unmangled_name[i] == ':' ||
383 (is_extension && unmangled_name[i] == '#')) {
384 if (start != 0) {
385 // Reset and break.
386 start = 0;
387 dot_pos = -1;
388 break;
389 }
390 ASSERT(start == 0); // Only one : is possible in getters or setters.
391 if (unmangled_name[0] == 's') {
392 ASSERT(!is_setter);
393 is_setter = true;
394 }
395 start = i + 1;
396 } else if (unmangled_name[i] == '.') {
397 if (dot_pos != -1) {
398 // Reset and break.
399 start = 0;
400 dot_pos = -1;
401 break;
402 }
403 ASSERT(dot_pos == -1); // Only one dot is supported.
404 dot_pos = i;
405 }
406 }
407
408 if (!is_extension && (start == 0) && (dot_pos == -1)) {
409 // This unmangled_name is fine as it is.
410 return unmangled_name;
411 }
412
413 // Drop the trailing dot if needed.
414 intptr_t end = ((dot_pos + 1) == len) ? dot_pos : len;
415
416 intptr_t substr_len = end - start;
417 AppendSubString(&printer, unmangled_name, start, substr_len);
418 if (is_setter) {
419 const char* equals = Symbols::Equals().ToCString();
420 const intptr_t equals_len = strlen(equals);
421 AppendSubString(&printer, equals, 0, equals_len);
422 }
423
424 return printer.buffer();
425}
bool equals(SkDrawable *a, SkDrawable *b)
friend class Thread
Definition: object.h:1025
static const char * ToCString(Thread *thread, StringPtr ptr)
Definition: object.cc:24126
static const String & Equals()
Definition: symbols.h:614
static void AppendSubString(BaseTextBuffer *buffer, const char *name, intptr_t start_pos, intptr_t len)
Definition: object.cc:193

◆ ScrubNameRetainPrivate()

StringPtr dart::String::ScrubNameRetainPrivate ( const String name,
bool  is_extension = false 
)
static

Definition at line 427 of file object.cc.

428 {
429#if !defined(DART_PRECOMPILED_RUNTIME)
430 intptr_t len = name.Length();
431 intptr_t start = 0;
432 intptr_t at_pos = -1; // Position of '@' in the name, if any.
433 bool is_setter = false;
434
435 String& result = String::Handle();
436
437 // If extension strip out the leading prefix e.g" ext|func would strip out
438 // 'ext|'.
439 if (is_extension) {
440 // First scan till we see the '|' character.
441 for (intptr_t i = 0; i < len; i++) {
442 if (name.CharAt(i) == '|') {
443 result = String::SubString(name, start, (i - start));
445 start = i + 1;
446 break;
447 } else if (name.CharAt(i) == ':') {
448 if (start != 0) {
449 // Reset and break.
450 start = 0;
451 is_setter = false;
452 break;
453 }
454 if (name.CharAt(0) == 's') {
455 is_setter = true;
456 }
457 start = i + 1;
458 }
459 }
460 }
461
462 for (intptr_t i = start; i < len; i++) {
463 if (name.CharAt(i) == ':' || (is_extension && name.CharAt(i) == '#')) {
464 // Only one : is possible in getters or setters.
465 ASSERT(is_extension || start == 0);
466 if (name.CharAt(start) == 's') {
467 is_setter = true;
468 }
469 start = i + 1;
470 } else if (name.CharAt(i) == '@') {
471 // Setters should have only one @ so we know where to put the =.
472 ASSERT(!is_setter || (at_pos == -1));
473 at_pos = i;
474 }
475 }
476
477 if (start == 0) {
478 // This unmangled_name is fine as it is.
479 return name.ptr();
480 }
481
482 if (is_extension) {
483 const String& fname =
484 String::Handle(String::SubString(name, start, (len - start)));
485 result = String::Concat(result, fname);
486 } else {
487 result = String::SubString(name, start, (len - start));
488 }
489
490 if (is_setter) {
491 // Setters need to end with '='.
492 if (at_pos == -1) {
494 } else {
495 const String& pre_at =
496 String::Handle(String::SubString(result, 0, at_pos - 4));
497 const String& post_at =
498 String::Handle(String::SubString(name, at_pos, len - at_pos));
500 result = String::Concat(result, post_at);
501 }
502 }
503
504 return result.ptr();
505#endif // !defined(DART_PRECOMPILED_RUNTIME)
506 return name.ptr(); // In AOT, return argument unchanged.
507}
static StringPtr SubString(const String &str, intptr_t begin_index, Heap::Space space=Heap::kNew)
Definition: object.cc:24080
static StringPtr Concat(const String &str1, const String &str2, Heap::Space space=Heap::kNew)
Definition: object.cc:24037
static const String & Dot()
Definition: symbols.h:613

◆ SetCachedHash()

static uint32_t dart::String::SetCachedHash ( StringPtr  obj,
uint32_t  hash 
)
inlinestatic

Definition at line 10454 of file object.h.

10454 {
10455 obj->untag()->hash_ = Smi::New(hash);
10456 return hash;
10457 }
static uint32_t hash(const SkShaderBase::GradientInfo &v)

◆ SetCachedHashIfNotSet()

static uint32_t dart::String::SetCachedHashIfNotSet ( StringPtr  obj,
uint32_t  hash 
)
inlinestatic

Definition at line 10449 of file object.h.

10449 {
10450 ASSERT(Smi::Value(obj->untag()->hash_) == 0 ||
10451 Smi::Value(obj->untag()->hash_) == static_cast<intptr_t>(hash));
10452 return SetCachedHash(obj, hash);
10453 }
static uint32_t SetCachedHash(StringPtr obj, uint32_t hash)
Definition: object.h:10454

◆ SetHash()

void dart::String::SetHash ( intptr_t  value) const
inlineprotected

Definition at line 10477 of file object.h.

10477 {
10478 const intptr_t hash_set = SetCachedHashIfNotSet(ptr(), value);
10479 ASSERT(hash_set == value);
10480 }
uint8_t value

◆ SetLength()

void dart::String::SetLength ( intptr_t  value) const
inlineprotected

Definition at line 10471 of file object.h.

10471 {
10472 // This is only safe because we create a new Smi, which does not cause
10473 // heap allocation.
10474 untag()->set_length(Smi::New(value));
10475 }

◆ StartsWith() [1/2]

bool dart::String::StartsWith ( const String other) const
inline

Definition at line 10298 of file object.h.

10298 {
10299 NoSafepointScope no_safepoint;
10300 return StartsWith(ptr(), other.ptr());
10301 }
bool StartsWith(const String &other) const
Definition: object.h:10298

◆ StartsWith() [2/2]

bool dart::String::StartsWith ( StringPtr  str,
StringPtr  prefix 
)
static

Definition at line 23657 of file object.cc.

23657 {
23658 if (prefix == String::null()) return false;
23659
23660 const intptr_t length = String::LengthOf(str);
23661 const intptr_t prefix_length = String::LengthOf(prefix);
23662 if (prefix_length > length) return false;
23663
23664 for (intptr_t i = 0; i < prefix_length; i++) {
23665 if (String::CharAt(str, i) != String::CharAt(prefix, i)) {
23666 return false;
23667 }
23668 }
23669 return true;
23670}

◆ SubString() [1/3]

StringPtr dart::String::SubString ( const String str,
intptr_t  begin_index,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24080 of file object.cc.

24082 {
24083 ASSERT(!str.IsNull());
24084 if (begin_index >= str.Length()) {
24085 return String::null();
24086 }
24087 return String::SubString(str, begin_index, (str.Length() - begin_index),
24088 space);
24089}

◆ SubString() [2/3]

static StringPtr dart::String::SubString ( const String str,
intptr_t  begin_index,
intptr_t  length,
Heap::Space  space = Heap::kNew 
)
inlinestatic

Definition at line 10403 of file object.h.

10406 {
10407 return SubString(Thread::Current(), str, begin_index, length, space);
10408 }

◆ SubString() [3/3]

StringPtr dart::String::SubString ( Thread thread,
const String str,
intptr_t  begin_index,
intptr_t  length,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24091 of file object.cc.

24095 {
24096 ASSERT(!str.IsNull());
24097 ASSERT(begin_index >= 0);
24098 ASSERT(length >= 0);
24099 if (begin_index <= str.Length() && length == 0) {
24100 return Symbols::Empty().ptr();
24101 }
24102 if (begin_index > str.Length()) {
24103 return String::null();
24104 }
24105 bool is_one_byte_string = true;
24106 intptr_t char_size = str.CharSize();
24107 if (char_size == kTwoByteChar) {
24108 for (intptr_t i = begin_index; i < begin_index + length; ++i) {
24109 if (!Utf::IsLatin1(str.CharAt(i))) {
24110 is_one_byte_string = false;
24111 break;
24112 }
24113 }
24114 }
24116 String& result = thread->StringHandle();
24117 if (is_one_byte_string) {
24119 } else {
24121 }
24122 String::Copy(result, 0, str, begin_index, length);
24123 return result.ptr();
24124}
static const String & Empty()
Definition: symbols.h:688
#define REUSABLE_STRING_HANDLESCOPE(thread)

◆ ToCString()

const char * dart::String::ToCString ( Thread thread,
StringPtr  ptr 
)
static

Definition at line 24126 of file object.cc.

24126 {
24127 if (IsNull()) {
24128 return "String: null";
24129 }
24130 const intptr_t len = Utf8::Length(*this);
24131 Zone* zone = Thread::Current()->zone();
24132 uint8_t* result = zone->Alloc<uint8_t>(len + 1);
24133 ToUTF8(result, len);
24134 result[len] = 0;
24135 return reinterpret_cast<const char*>(result);
24136}
bool IsNull() const
Definition: object.h:363
void ToUTF8(uint8_t *utf8_array, intptr_t array_len) const
Definition: object.cc:24146

◆ ToLowerCase()

StringPtr dart::String::ToLowerCase ( const String str,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24202 of file object.cc.

24202 {
24203 // TODO(cshapiro): create a fast-path for OneByteString instances.
24204 return Transform(CaseMapping::ToLower, str, space);
24205}
static int32_t ToLower(int32_t code_point)
Definition: unicode.h:179
static StringPtr Transform(int32_t(*mapping)(int32_t ch), const String &str, Heap::Space space=Heap::kNew)
Definition: object.cc:24172

◆ ToMallocCString()

char * dart::String::ToMallocCString ( ) const

Definition at line 24138 of file object.cc.

24138 {
24139 const intptr_t len = Utf8::Length(*this);
24140 uint8_t* result = reinterpret_cast<uint8_t*>(malloc(len + 1));
24141 ToUTF8(result, len);
24142 result[len] = 0;
24143 return reinterpret_cast<char*>(result);
24144}
void * malloc(size_t size)
Definition: allocation.cc:19

◆ ToUpperCase()

StringPtr dart::String::ToUpperCase ( const String str,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24197 of file object.cc.

24197 {
24198 // TODO(cshapiro): create a fast-path for OneByteString instances.
24199 return Transform(CaseMapping::ToUpper, str, space);
24200}
static int32_t ToUpper(int32_t code_point)
Definition: unicode.h:174

◆ ToUTF8()

void dart::String::ToUTF8 ( uint8_t *  utf8_array,
intptr_t  array_len 
) const

Definition at line 24146 of file object.cc.

24146 {
24147 ASSERT(array_len >= Utf8::Length(*this));
24148 Utf8::Encode(*this, reinterpret_cast<char*>(utf8_array), array_len);
24149}
static intptr_t Encode(int32_t ch, char *dst)
Definition: unicode.cc:110

◆ Transform()

StringPtr dart::String::Transform ( int32_t(*)(int32_t ch)  mapping,
const String str,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24172 of file object.cc.

24174 {
24175 ASSERT(!str.IsNull());
24176 bool has_mapping = false;
24177 int32_t dst_max = 0;
24178 CodePointIterator it(str);
24179 while (it.Next()) {
24180 int32_t src = it.Current();
24181 int32_t dst = mapping(src);
24182 if (src != dst) {
24183 has_mapping = true;
24184 }
24185 dst_max = Utils::Maximum(dst_max, dst);
24186 }
24187 if (!has_mapping) {
24188 return str.ptr();
24189 }
24190 if (Utf::IsLatin1(dst_max)) {
24191 return OneByteString::Transform(mapping, str, space);
24192 }
24193 ASSERT(Utf::IsBmp(dst_max) || Utf::IsSupplementary(dst_max));
24194 return TwoByteString::Transform(mapping, str, space);
24195}
static OneByteStringPtr Transform(int32_t(*mapping)(int32_t ch), const String &str, Heap::Space space)
Definition: object.cc:24494
static TwoByteStringPtr Transform(int32_t(*mapping)(int32_t ch), const String &str, Heap::Space space)
Definition: object.cc:24673
static bool IsBmp(int32_t code_point)
Definition: unicode.h:27

Friends And Related Function Documentation

◆ CharArray

template<typename CharType >
friend class CharArray
friend

Definition at line 10488 of file object.h.

◆ Class

friend class Class
friend

Definition at line 10484 of file object.h.

◆ ConcatString

friend class ConcatString
friend

Definition at line 10489 of file object.h.

◆ OneByteString

friend class OneByteString
friend

Definition at line 10490 of file object.h.

◆ Pass2Visitor

friend class Pass2Visitor
friend

Definition at line 10494 of file object.h.

◆ RODataSerializationCluster

friend class RODataSerializationCluster
friend

Definition at line 10493 of file object.h.

◆ StringSlice

friend class StringSlice
friend

Definition at line 10486 of file object.h.

◆ Symbols

friend class Symbols
friend

Definition at line 10485 of file object.h.

◆ TwoByteString

friend class TwoByteString
friend

Definition at line 10491 of file object.h.

◆ UntaggedOneByteString

friend class UntaggedOneByteString
friend

Definition at line 10492 of file object.h.

Member Data Documentation

◆ kMaxElements

constexpr intptr_t dart::String::kMaxElements = kSmiMax / kTwoByteChar
staticconstexpr

Definition at line 10173 of file object.h.

◆ kOneByteChar

constexpr intptr_t dart::String::kOneByteChar = 1
staticconstexpr

Definition at line 10160 of file object.h.

◆ kSizeofRawString

constexpr intptr_t dart::String::kSizeofRawString
staticconstexpr
Initial value:
=
sizeof(UntaggedInstance) + 2 * kWordSize
constexpr intptr_t kWordSize
Definition: globals.h:509

Definition at line 10170 of file object.h.

◆ kTwoByteChar

constexpr intptr_t dart::String::kTwoByteChar = 2
staticconstexpr

Definition at line 10161 of file object.h.


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