]>
git.saurik.com Git - apple/javascriptcore.git/blob - API/JSStringRef.h
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <JavaScriptCore/JSValueRef.h>
34 #include <stddef.h> /* for size_t */
40 #if !defined(WIN32) && !defined(_WIN32)
43 @abstract A Unicode character.
45 typedef unsigned short JSChar
;
47 typedef wchar_t JSChar
;
52 @abstract Creates a JavaScript string from a buffer of Unicode characters.
53 @param chars The buffer of Unicode characters to copy into the new JSString.
54 @param numChars The number of characters to copy from the buffer pointed to by chars.
55 @result A JSString containing chars. Ownership follows the Create Rule.
57 JS_EXPORT JSStringRef
JSStringCreateWithCharacters(const JSChar
* chars
, size_t numChars
);
60 @abstract Creates a JavaScript string from a null-terminated UTF8 string.
61 @param string The null-terminated UTF8 string to copy into the new JSString.
62 @result A JSString containing string. Ownership follows the Create Rule.
64 JS_EXPORT JSStringRef
JSStringCreateWithUTF8CString(const char* string
);
68 @abstract Retains a JavaScript string.
69 @param string The JSString to retain.
70 @result A JSString that is the same as string.
72 JS_EXPORT JSStringRef
JSStringRetain(JSStringRef string
);
75 @abstract Releases a JavaScript string.
76 @param string The JSString to release.
78 JS_EXPORT
void JSStringRelease(JSStringRef string
);
82 @abstract Returns the number of Unicode characters in a JavaScript string.
83 @param string The JSString whose length (in Unicode characters) you want to know.
84 @result The number of Unicode characters stored in string.
86 JS_EXPORT
size_t JSStringGetLength(JSStringRef string
);
89 @abstract Returns a pointer to the Unicode character buffer that
90 serves as the backing store for a JavaScript string.
91 @param string The JSString whose backing store you want to access.
92 @result A pointer to the Unicode character buffer that serves as string's
93 backing store, which will be deallocated when string is deallocated.
95 JS_EXPORT
const JSChar
* JSStringGetCharactersPtr(JSStringRef string
);
99 @abstract Returns the maximum number of bytes a JavaScript string will
100 take up if converted into a null-terminated UTF8 string.
101 @param string The JSString whose maximum converted size (in bytes) you
103 @result The maximum number of bytes that could be required to convert string into a
104 null-terminated UTF8 string. The number of bytes that the conversion actually ends
105 up requiring could be less than this, but never more.
107 JS_EXPORT
size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string
);
110 @abstract Converts a JavaScript string into a null-terminated UTF8 string,
111 and copies the result into an external byte buffer.
112 @param string The source JSString.
113 @param buffer The destination byte buffer into which to copy a null-terminated
114 UTF8 representation of string. On return, buffer contains a UTF8 string
115 representation of string. If bufferSize is too small, buffer will contain only
116 partial results. If buffer is not at least bufferSize bytes in size,
117 behavior is undefined.
118 @param bufferSize The size of the external buffer in bytes.
119 @result The number of bytes written into buffer (including the null-terminator byte).
121 JS_EXPORT
size_t JSStringGetUTF8CString(JSStringRef string
, char* buffer
, size_t bufferSize
);
125 @abstract Tests whether two JavaScript strings match.
126 @param a The first JSString to test.
127 @param b The second JSString to test.
128 @result true if the two strings match, otherwise false.
130 JS_EXPORT
bool JSStringIsEqual(JSStringRef a
, JSStringRef b
);
133 @abstract Tests whether a JavaScript string matches a null-terminated UTF8 string.
134 @param a The JSString to test.
135 @param b The null-terminated UTF8 string to test.
136 @result true if the two strings match, otherwise false.
138 JS_EXPORT
bool JSStringIsEqualToUTF8CString(JSStringRef a
, const char* b
);
144 #endif /* JSStringRef_h */