1 | // -*- mode: c++; c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | *
|
---|
14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
---|
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
---|
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef JSStringRef_h
|
---|
28 | #define JSStringRef_h
|
---|
29 |
|
---|
30 | #include <JavaScriptCore/JSValueRef.h>
|
---|
31 |
|
---|
32 | #include <stdbool.h>
|
---|
33 | #include <stddef.h> // for size_t
|
---|
34 |
|
---|
35 | #ifdef __cplusplus
|
---|
36 | extern "C" {
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #if defined(__APPLE__)
|
---|
40 | #include <JavaScriptCore/JSStringRefCF.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | /*!
|
---|
44 | @typedef JSChar
|
---|
45 | @abstract A Unicode character.
|
---|
46 | */
|
---|
47 | #if !defined(WIN32) && !defined(_WIN32)
|
---|
48 | typedef unsigned short JSChar;
|
---|
49 | #else
|
---|
50 | typedef wchar_t JSChar;
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | /*!
|
---|
54 | @function
|
---|
55 | @abstract Creates a JavaScript string from a buffer of Unicode characters.
|
---|
56 | @param chars The buffer of Unicode characters to copy into the new JSString.
|
---|
57 | @param numChars The number of characters to copy from the buffer pointed to by chars.
|
---|
58 | @result A JSString containing chars. Ownership follows the Create Rule.
|
---|
59 | */
|
---|
60 | JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars);
|
---|
61 | /*!
|
---|
62 | @function
|
---|
63 | @abstract Creates a JavaScript string from a null-terminated UTF8 string.
|
---|
64 | @param string The null-terminated UTF8 string to copy into the new JSString.
|
---|
65 | @result A JSString containing string. Ownership follows the Create Rule.
|
---|
66 | */
|
---|
67 | JSStringRef JSStringCreateWithUTF8CString(const char* string);
|
---|
68 |
|
---|
69 | /*!
|
---|
70 | @function
|
---|
71 | @abstract Retains a JavaScript string.
|
---|
72 | @param string The JSString to retain.
|
---|
73 | @result A JSString that is the same as string.
|
---|
74 | */
|
---|
75 | JSStringRef JSStringRetain(JSStringRef string);
|
---|
76 | /*!
|
---|
77 | @function
|
---|
78 | @abstract Releases a JavaScript string.
|
---|
79 | @param string The JSString to release.
|
---|
80 | */
|
---|
81 | void JSStringRelease(JSStringRef string);
|
---|
82 |
|
---|
83 | /*!
|
---|
84 | @function
|
---|
85 | @abstract Returns the number of Unicode characters in a JavaScript string.
|
---|
86 | @param string The JSString whose length (in Unicode characters) you want to know.
|
---|
87 | @result The number of Unicode characters stored in string.
|
---|
88 | */
|
---|
89 | size_t JSStringGetLength(JSStringRef string);
|
---|
90 | /*!
|
---|
91 | @function
|
---|
92 | @abstract Returns a pointer to the Unicode character buffer that
|
---|
93 | serves as the backing store for a JavaScript string.
|
---|
94 | @param string The JSString whose backing store you want to access.
|
---|
95 | @result A pointer to the Unicode character buffer that serves as string's
|
---|
96 | backing store, which will be deallocated when string is deallocated.
|
---|
97 | */
|
---|
98 | const JSChar* JSStringGetCharactersPtr(JSStringRef string);
|
---|
99 |
|
---|
100 | /*!
|
---|
101 | @function
|
---|
102 | @abstract Returns the maximum number of bytes a JavaScript string will
|
---|
103 | take up if converted into a null-terminated UTF8 string.
|
---|
104 | @param string The JSString whose maximum converted size (in bytes) you
|
---|
105 | want to know.
|
---|
106 | @result The maximum number of bytes that could be required to convert string into a
|
---|
107 | null-terminated UTF8 string. The number of bytes that the conversion actually ends
|
---|
108 | up requiring could be less than this, but never more.
|
---|
109 | */
|
---|
110 | size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string);
|
---|
111 | /*!
|
---|
112 | @function
|
---|
113 | @abstract Converts a JavaScript string into a null-terminated UTF8 string,
|
---|
114 | and copies the result into an external byte buffer.
|
---|
115 | @param string The source JSString.
|
---|
116 | @param buffer The destination byte buffer into which to copy a null-terminated
|
---|
117 | UTF8 representation of string. On return, buffer contains a UTF8 string
|
---|
118 | representation of string. If bufferSize is too small, buffer will contain only
|
---|
119 | partial results. If buffer is not at least bufferSize bytes in size,
|
---|
120 | behavior is undefined.
|
---|
121 | @param bufferSize The size of the external buffer in bytes.
|
---|
122 | @result The number of bytes written into buffer (including the null-terminator byte).
|
---|
123 | */
|
---|
124 | size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize);
|
---|
125 |
|
---|
126 | /*!
|
---|
127 | @function
|
---|
128 | @abstract Tests whether two JavaScript strings match.
|
---|
129 | @param a The first JSString to test.
|
---|
130 | @param b The second JSString to test.
|
---|
131 | @result true if the two strings match, otherwise false.
|
---|
132 | */
|
---|
133 | bool JSStringIsEqual(JSStringRef a, JSStringRef b);
|
---|
134 | /*!
|
---|
135 | @function
|
---|
136 | @abstract Tests whether a JavaScript string matches a null-terminated UTF8 string.
|
---|
137 | @param a The JSString to test.
|
---|
138 | @param b The null-terminated UTF8 string to test.
|
---|
139 | @result true if the two strings match, otherwise false.
|
---|
140 | */
|
---|
141 | bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
|
---|
142 |
|
---|
143 | #ifdef __cplusplus
|
---|
144 | }
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | #endif // JSStringRef_h
|
---|