v8  3.11.10(node0.8.26)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
String Class Reference

#include <v8.h>

Inheritance diagram for String:
Collaboration diagram for String:

Data Structures

class  AsciiValue
 
class  ExternalAsciiStringResource
 
class  ExternalStringResource
 
class  ExternalStringResourceBase
 
class  Utf8Value
 
class  Value
 

Public Types

enum  WriteOptions { NO_OPTIONS = 0, HINT_MANY_WRITES_EXPECTED = 1, NO_NULL_TERMINATION = 2 }
 

Public Member Functions

V8EXPORT int Length () const
 
V8EXPORT int Utf8Length () const
 
V8EXPORT bool MayContainNonAscii () const
 
V8EXPORT int Write (uint16_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
 
V8EXPORT int WriteAscii (char *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
 
V8EXPORT int WriteUtf8 (char *buffer, int length=-1, int *nchars_ref=NULL, int options=NO_OPTIONS) const
 
V8EXPORT bool IsExternal () const
 
V8EXPORT bool IsExternalAscii () const
 
ExternalStringResourceGetExternalStringResource () const
 
V8EXPORT const
ExternalAsciiStringResource
GetExternalAsciiStringResource () const
 
V8EXPORT bool MakeExternal (ExternalStringResource *resource)
 
V8EXPORT bool MakeExternal (ExternalAsciiStringResource *resource)
 
V8EXPORT bool CanMakeExternal ()
 
- Public Member Functions inherited from Value
bool IsUndefined () const
 
bool IsNull () const
 
V8EXPORT bool IsTrue () const
 
V8EXPORT bool IsFalse () const
 
bool IsString () const
 
V8EXPORT bool IsFunction () const
 
V8EXPORT bool IsArray () const
 
V8EXPORT bool IsObject () const
 
V8EXPORT bool IsBoolean () const
 
V8EXPORT bool IsNumber () const
 
V8EXPORT bool IsExternal () const
 
V8EXPORT bool IsInt32 () const
 
V8EXPORT bool IsUint32 () const
 
V8EXPORT bool IsDate () const
 
V8EXPORT bool IsBooleanObject () const
 
V8EXPORT bool IsNumberObject () const
 
V8EXPORT bool IsStringObject () const
 
V8EXPORT bool IsNativeError () const
 
V8EXPORT bool IsRegExp () const
 
V8EXPORT Local< BooleanToBoolean () const
 
V8EXPORT Local< NumberToNumber () const
 
V8EXPORT Local< StringToString () const
 
V8EXPORT Local< StringToDetailString () const
 
V8EXPORT Local< ObjectToObject () const
 
V8EXPORT Local< IntegerToInteger () const
 
V8EXPORT Local< Uint32ToUint32 () const
 
V8EXPORT Local< Int32ToInt32 () const
 
V8EXPORT Local< Uint32ToArrayIndex () const
 
V8EXPORT bool BooleanValue () const
 
V8EXPORT double NumberValue () const
 
V8EXPORT int64_t IntegerValue () const
 
V8EXPORT uint32_t Uint32Value () const
 
V8EXPORT int32_t Int32Value () const
 
V8EXPORT bool Equals (Handle< Value > that) const
 
V8EXPORT bool StrictEquals (Handle< Value > that) const
 

Static Public Member Functions

static V8EXPORT v8::Local
< v8::String
Empty ()
 
static v8::Local< v8::StringEmpty (Isolate *isolate)
 
static StringCast (v8::Value *obj)
 
static V8EXPORT Local< StringNew (const char *data, int length=-1)
 
static V8EXPORT Local< StringNew (const uint16_t *data, int length=-1)
 
static V8EXPORT Local< StringNewSymbol (const char *data, int length=-1)
 
static V8EXPORT Local< StringConcat (Handle< String > left, Handle< String > right)
 
static V8EXPORT Local< StringNewExternal (ExternalStringResource *resource)
 
static V8EXPORT Local< StringNewExternal (ExternalAsciiStringResource *resource)
 
static V8EXPORT Local< StringNewUndetectable (const char *data, int length=-1)
 
static V8EXPORT Local< StringNewUndetectable (const uint16_t *data, int length=-1)
 

Detailed Description

A JavaScript string value (ECMA-262, 4.3.17).

Definition at line 1018 of file v8.h.

Member Enumeration Documentation

Write the contents of the string to an external buffer. If no arguments are given, expects the buffer to be large enough to hold the entire string and NULL terminator. Copies the contents of the string and the NULL terminator into the buffer.

WriteUtf8 will not write partial UTF-8 sequences, preferring to stop before the end of the buffer.

Copies up to length characters into the output buffer. Only null-terminates if there is enough space in the buffer.

Parameters
bufferThe buffer into which the string will be copied.
startThe starting position within the string at which copying begins.
lengthThe number of characters to copy from the string. For WriteUtf8 the number of bytes in the buffer.
nchars_refThe number of characters written, can be NULL.
optionsVarious options that might affect performance of this or subsequent operations.
Returns
The number of characters copied to the buffer excluding the null terminator. For WriteUtf8: The number of bytes copied to the buffer including the null terminator (if written).
Enumerator
NO_OPTIONS 
HINT_MANY_WRITES_EXPECTED 
NO_NULL_TERMINATION 

Definition at line 1064 of file v8.h.

Member Function Documentation

bool CanMakeExternal ( )

Returns true if this string can be made external.

Definition at line 4816 of file api.cc.

References StringTracker::IsFreshUnusedString(), ExternalString::kShortSize, Utils::OpenHandle(), and Isolate::string_tracker().

String * Cast ( v8::Value obj)
inlinestatic

Definition at line 4242 of file v8.h.

Referenced by ReadLine(), and TEST().

Local< String > Concat ( Handle< String left,
Handle< String right 
)
static

Creates a new string by concatenating the left and the right strings passed in as parameters.

Definition at line 4669 of file api.cc.

References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewConsString(), Utils::OpenHandle(), and Utils::ToLocal().

Referenced by Shell::ReadFromStdin().

Local< String > Empty ( )
static

A zero length string.

Definition at line 4645 of file api.cc.

References Isolate::factory(), LOG_API, and Utils::ToLocal().

Referenced by String::Empty(), and TEST().

Local< String > Empty ( Isolate isolate)
inlinestatic

Definition at line 4250 of file v8.h.

References String::Empty(), I, and S.

const v8::String::ExternalAsciiStringResource * GetExternalAsciiStringResource ( ) const

Get the ExternalAsciiStringResource for an external ASCII string. Returns NULL if IsExternalAscii() doesn't return true.

Definition at line 4058 of file api.cc.

References Handle< T >::cast(), NULL, and Utils::OpenHandle().

String::ExternalStringResource * GetExternalStringResource ( ) const
inline

Get the ExternalStringResource for an external string. Returns NULL if IsExternal() doesn't return true.

Definition at line 4259 of file v8.h.

References I, and NULL.

bool IsExternal ( ) const

Returns true if the string is external

Definition at line 4023 of file api.cc.

References Utils::OpenHandle().

Referenced by TEST(), and VisitorImpl::VisitExternalString().

bool IsExternalAscii ( ) const

Returns true if the string is both external and ASCII

Definition at line 4033 of file api.cc.

References Utils::OpenHandle().

Referenced by VisitorImpl::VisitExternalString().

int Length ( ) const

Returns the number of characters in this string.

Definition at line 3718 of file api.cc.

References Utils::OpenHandle().

Referenced by String::AsciiValue::AsciiValue(), PrintExtension::Print(), TEST(), THREADED_TEST(), and String::Value::Value().

bool MakeExternal ( ExternalStringResource resource)

Associate an external string resource with this string by transforming it in place so that existing references to this string in the JavaScript heap will use the external string resource. The external string resource's character contents need to be equivalent to this string. Returns true if the string has been changed to be an external string. The string is not modified if the operation fails. See NewExternal for information on the lifetime of the resource.

Definition at line 4759 of file api.cc.

References ExternalStringTable::AddString(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), StringTracker::IsFreshUnusedString(), Heap::IsInGCPostProcessing(), Utils::OpenHandle(), and Isolate::string_tracker().

bool MakeExternal ( ExternalAsciiStringResource resource)

Associate an external string resource with this string by transforming it in place so that existing references to this string in the JavaScript heap will use the external string resource. The external string resource's character contents need to be equivalent to this string. Returns true if the string has been changed to be an external string. The string is not modified if the operation fails. See NewExternal for information on the lifetime of the resource.

Definition at line 4793 of file api.cc.

References ExternalStringTable::AddString(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), StringTracker::IsFreshUnusedString(), Heap::IsInGCPostProcessing(), Utils::OpenHandle(), and Isolate::string_tracker().

bool MayContainNonAscii ( ) const

A fast conservative check for non-ASCII characters. May return true even for ASCII strings, but if it returns false you can be sure that all characters are in the range 0-127.

Definition at line 3820 of file api.cc.

References Utils::OpenHandle().

Local< String > New ( const char *  data,
int  length = -1 
)
static

Allocates a new string from either UTF-8 encoded or ASCII data. The second parameter 'length' gives the buffer length. If the data is UTF-8 encoded, the caller must be careful to supply the length parameter. If it is not given, the function calls 'strlen' to determine the buffer length, it might be wrong if 'data' contains a null character.

Definition at line 4655 of file api.cc.

References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromUtf8(), v8::internal::StrLength(), and Utils::ToLocal().

Referenced by Shell::AddOSMethods(), Shell::ChangeDirectory(), Shell::CreateEvaluationContext(), CreateGlobalTemplate(), CreateShellContext(), DEPENDENT_TEST(), DoLoop(), DoLoopNoCall(), SourceGroup::Execute(), ExternalizeStringExtension::Externalize(), Shell::GetCompletions(), ProfilerExtension::GetNativeFunction(), ExecArgs::Init(), ExternalizeStringExtension::IsAscii(), Load(), Shell::Load(), Loop(), LoopGetProperty(), Shell::MakeDirectory(), Object::ObjectProtoToString(), ReadLineEditor::Prompt(), Read(), Shell::Read(), Shell::ReadBuffer(), ReadFile(), Shell::ReadFile(), Shell::ReadFromStdin(), ReadLine(), ReenterAfterTermination(), Shell::RemoveDirectory(), ThreadA::Run(), LoopingThread::Run(), ShellThread::Run(), RunCppCycle(), RunMain(), RunShell(), Template::Set(), Shell::SetEnvironment(), Shell::SetUMask(), ProfilerExtension::StartProfiling(), ProfilerExtension::StopProfiling(), Shell::System(), TerminateOrReturnObject(), TEST(), THREADED_TEST(), Shell::UnsetEnvironment(), Version(), and Shell::Version().

Local< String > New ( const uint16_t *  data,
int  length = -1 
)
static

Allocates a new string from 16-bit character codes.

Definition at line 4703 of file api.cc.

References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromTwoByte(), and Utils::ToLocal().

Local< String > NewExternal ( ExternalStringResource resource)
static

Creates a new external string using the data defined in the given resource. When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource.

Definition at line 4747 of file api.cc.

References ExternalStringTable::AddString(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), LOG_API, v8::NewExternalStringHandle(), and Utils::ToLocal().

Referenced by TEST().

Local< String > NewExternal ( ExternalAsciiStringResource resource)
static

Creates a new external string using the ASCII data defined in the given resource. When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource.

Definition at line 4781 of file api.cc.

References ExternalStringTable::AddString(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), LOG_API, v8::NewExternalAsciiStringHandle(), and Utils::ToLocal().

Local< String > NewSymbol ( const char *  data,
int  length = -1 
)
static

Creates a symbol. Returns one if it exists already.

Definition at line 5075 of file api.cc.

References ENTER_V8, Isolate::factory(), LOG_API, Factory::LookupSymbol(), v8::internal::StrLength(), and Utils::ToLocal().

Referenced by THREADED_TEST().

Local< String > NewUndetectable ( const char *  data,
int  length = -1 
)
static

Creates an undetectable string from the supplied ASCII or UTF-8 data.

Definition at line 4682 of file api.cc.

References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromUtf8(), v8::internal::StrLength(), and Utils::ToLocal().

Local< String > NewUndetectable ( const uint16_t *  data,
int  length = -1 
)
static

Creates an undetectable string from the supplied 16-bit character codes.

Definition at line 4717 of file api.cc.

References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromTwoByte(), and Utils::ToLocal().

int Utf8Length ( ) const

Returns the number of bytes in the UTF-8 encoded representation of this string.

Definition at line 3725 of file api.cc.

References Utils::OpenHandle(), and v8::internal::Utf8Length().

Referenced by TEST().

int Write ( uint16_t *  buffer,
int  start = 0,
int  length = -1,
int  options = NO_OPTIONS 
) const

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