Debian Codegraph @

src/3rdparty/javascriptcore/JavaScriptCore/API/JSStringRef.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2006, 2007 Apple 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 #include "config.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/config.h`/
27 #include "JSStringRef.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/API/JSStringRef.h`/
28
29 #include "InitializeThreading.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/InitializeThreading.h`/
30 #include "OpaqueJSString.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/API/OpaqueJSString.h`/
31 #include <wtf/unicode/UTF8.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/unicode/UTF8.h`/
32
33 using namespace JSCcxx . . $ `<built-in>:463:9`!;
34 using namespace WTFcxx . . $ `<built-in>:467:9`!::Unicode;
35
36 JSStringRefcxx . . $ JSStringRef# JSStringCreateWithCharacterscxx . . $ JSStringCreateWithCharacters(4247fae16c809ee1).(const JSChar* chars, size_tcxx . . $ size_t# numChars)
37 {
38 initializeThreadingcxx . . $ QTJSC/initializeThreading(49f6e7a06ebc5aa8).();
39 return OpaqueJSStringcxx . . $ OpaqueJSString#::createcxx . . $ OpaqueJSString#create(66b7c7959bf32be2).(chars, numChars).releaseRef();
40 }
41
42 JSStringRefcxx . . $ JSStringRef# JSStringCreateWithUTF8CStringcxx . . $ JSStringCreateWithUTF8CString(69d1e63ed175ffe3).(const char* string)
43 {
44 initializeThreadingcxx . . $ QTJSC/initializeThreading(49f6e7a06ebc5aa8).();
45 if (string) {
46 size_tcxx . . $ size_t# length = strlen(string);
47 Vectorcxx . . $ Vector#<UCharcxx . . $ UChar#, 1024> buffer(length);
48 UCharcxx . . $ UChar#* p = buffer.data();
49 if (conversionOKcxx . . $ QTWTF/Unicode/conversionOK. == convertUTF8ToUTF16cxx . . $ QTWTF/Unicode/convertUTF8ToUTF16(de240f0d207e4f19).(&string, string + length, &p, p + length))
50 return OpaqueJSStringcxx . . $ OpaqueJSString#::createcxx . . $ OpaqueJSString#create(66b7c7959bf32be2).(buffer.data(), p - buffer.data()).releaseRef();
51 }
52
53 // Null string.
54 return OpaqueJSStringcxx . . $ OpaqueJSString#::createcxx . . $ OpaqueJSString#create(66b7c7959bf32be2).().releaseRef();
55 }
56
57 JSStringRefcxx . . $ JSStringRef# JSStringRetaincxx . . $ JSStringRetain(9ff844e09f1d17d4).(JSStringRefcxx . . $ JSStringRef# string)
58 {
59 string->ref();
60 return string;
61 }
62
63 void JSStringReleasecxx . . $ JSStringRelease(1ebc78f313a0a2cd).(JSStringRefcxx . . $ JSStringRef# string)
64 {
65 string->deref();
66 }
67
68 size_tcxx . . $ size_t# JSStringGetLengthcxx . . $ JSStringGetLength(2c38a5117868f24b).(JSStringRefcxx . . $ JSStringRef# string)
69 {
70 return string ? string->lengthcxx . . $ OpaqueJSString#length(db52760e79bf9054).() : 0;
71 }
72
73 const JSChar* JSStringGetCharactersPtrcxx . . $ JSStringGetCharactersPtr(5f0fa7d0822011ac).(JSStringRefcxx . . $ JSStringRef# string)
74 {
75 return string ? string->characterscxx . . $ OpaqueJSString#characters(8d440dcdf69a1816).() : nullptr;
76 }
77
78 size_tcxx . . $ size_t# JSStringGetMaximumUTF8CStringSizecxx . . $ JSStringGetMaximumUTF8CStringSize(2c38a5117868f24b).(JSStringRefcxx . . $ JSStringRef# string)
79 {
80 // Any UTF8 character > 3 bytes encodes as a UTF16 surrogate pair.
81 return string ? string->lengthcxx . . $ OpaqueJSString#length(db52760e79bf9054).() * 3 + 1 : 1; // + 1 for terminating '\0'
82 }
83
84 size_tcxx . . $ size_t# JSStringGetUTF8CStringcxx . . $ JSStringGetUTF8CString(a46124ca6a321858).(JSStringRefcxx . . $ JSStringRef# string, char* buffer, size_tcxx . . $ size_t# bufferSize)
85 {
86 if (!bufferSize)
87 return 0;
88
89 char* p = buffer;
90 ConversionResultcxx . . $ QTWTF/Unicode/ConversionResult# result = conversionOKcxx . . $ QTWTF/Unicode/conversionOK.;
91 if (string) {
92 const UCharcxx . . $ UChar#* d = string->characterscxx . . $ OpaqueJSString#characters(8d440dcdf69a1816).();
93 result = convertUTF16ToUTF8cxx . . $ QTWTF/Unicode/convertUTF16ToUTF8(c3351d9d7f212dbf).(&d, d + string->lengthcxx . . $ OpaqueJSString#length(db52760e79bf9054).(), &p, p + bufferSize - 1, true);
94 }
95 *p++ = '\0';
96 if (result != conversionOKcxx . . $ QTWTF/Unicode/conversionOK. && result != targetExhaustedcxx . . $ QTWTF/Unicode/targetExhausted.)
97 return 0;
98
99 return p - buffer;
100 }
101
102 bool JSStringIsEqualcxx . . $ JSStringIsEqual(eb2f893e8246295c).(JSStringRefcxx . . $ JSStringRef# a, JSStringRefcxx . . $ JSStringRef# b)
103 {
104 if (!a)
105 return (!b || b->lengthcxx . . $ OpaqueJSString#length(db52760e79bf9054).() == 0);
106 if (!b)
107 return (!a || a->lengthcxx . . $ OpaqueJSString#length(db52760e79bf9054).() == 0);
108 unsigned len = a->lengthcxx . . $ OpaqueJSString#length(db52760e79bf9054).();
109 return len == b->lengthcxx . . $ OpaqueJSString#length(db52760e79bf9054).() && 0 == memcmp(a->characterscxx . . $ OpaqueJSString#characters(8d440dcdf69a1816).(), b->characterscxx . . $ OpaqueJSString#characters(8d440dcdf69a1816).(), len * sizeof(UCharcxx . . $ UChar#));
110 }
111
112 bool JSStringIsEqualToUTF8CStringcxx . . $ JSStringIsEqualToUTF8CString(5a30f90ae2cb6ecc).(JSStringRefcxx . . $ JSStringRef# a, const char* b)
113 {
114 JSStringRefcxx . . $ JSStringRef# bBuf = JSStringCreateWithUTF8CStringcxx . . $ JSStringCreateWithUTF8CString(69d1e63ed175ffe3).(b);
115 bool result = JSStringIsEqualcxx . . $ JSStringIsEqual(eb2f893e8246295c).(a, bBuf);
116 JSStringReleasecxx . . $ JSStringRelease(1ebc78f313a0a2cd).(bBuf);
117
118 return result;
119 }