]> git.saurik.com Git - apple/javascriptcore.git/blame - API/JSStringRef.h
JavaScriptCore-521.tar.gz
[apple/javascriptcore.git] / API / JSStringRef.h
CommitLineData
b37bf2e1
A
1/*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#ifndef JSStringRef_h
27#define JSStringRef_h
28
29#include <JavaScriptCore/JSValueRef.h>
30
9dae56ea 31#ifndef __cplusplus
b37bf2e1 32#include <stdbool.h>
9dae56ea
A
33#endif
34#include <stddef.h> /* for size_t */
b37bf2e1
A
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#if !defined(WIN32) && !defined(_WIN32)
41/*!
42@typedef JSChar
43@abstract A Unicode character.
44*/
45 typedef unsigned short JSChar;
46#else
47 typedef wchar_t JSChar;
48#endif
49
50/*!
51@function
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.
56*/
57JS_EXPORT JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars);
58/*!
59@function
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.
63*/
64JS_EXPORT JSStringRef JSStringCreateWithUTF8CString(const char* string);
65
66/*!
67@function
68@abstract Retains a JavaScript string.
69@param string The JSString to retain.
70@result A JSString that is the same as string.
71*/
72JS_EXPORT JSStringRef JSStringRetain(JSStringRef string);
73/*!
74@function
75@abstract Releases a JavaScript string.
76@param string The JSString to release.
77*/
78JS_EXPORT void JSStringRelease(JSStringRef string);
79
80/*!
81@function
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.
85*/
86JS_EXPORT size_t JSStringGetLength(JSStringRef string);
87/*!
88@function
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.
94*/
95JS_EXPORT const JSChar* JSStringGetCharactersPtr(JSStringRef string);
96
97/*!
98@function
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
102 want to know.
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.
106*/
107JS_EXPORT size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string);
108/*!
109@function
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).
120*/
121JS_EXPORT size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize);
122
123/*!
124@function
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.
129*/
130JS_EXPORT bool JSStringIsEqual(JSStringRef a, JSStringRef b);
131/*!
132@function
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.
137*/
138JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
139
140#ifdef __cplusplus
141}
142#endif
143
9dae56ea 144#endif /* JSStringRef_h */