objc2_javascript_core/generated/JSStringRef.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4
5use crate::*;
6
7/// A UTF-16 code unit. One, or a sequence of two, can encode any Unicode
8/// character. As with all scalar types, endianness depends on the underlying
9/// architecture.
10///
11/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jschar?language=objc)
12pub type JSChar = c_ushort;
13
14extern "C-unwind" {
15 /// Creates a JavaScript string from a buffer of Unicode characters.
16 ///
17 /// Parameter `chars`: The buffer of Unicode characters to copy into the new JSString.
18 ///
19 /// Parameter `numChars`: The number of characters to copy from the buffer pointed to by chars.
20 ///
21 /// Returns: A JSString containing chars. Ownership follows the Create Rule.
22 #[cfg(feature = "JSBase")]
23 pub fn JSStringCreateWithCharacters(chars: *const JSChar, num_chars: usize) -> JSStringRef;
24}
25
26extern "C-unwind" {
27 /// Creates a JavaScript string from a null-terminated UTF8 string.
28 ///
29 /// Parameter `string`: The null-terminated UTF8 string to copy into the new JSString.
30 ///
31 /// Returns: A JSString containing string. Ownership follows the Create Rule.
32 #[cfg(feature = "JSBase")]
33 pub fn JSStringCreateWithUTF8CString(string: *const c_char) -> JSStringRef;
34}
35
36extern "C-unwind" {
37 /// Retains a JavaScript string.
38 ///
39 /// Parameter `string`: The JSString to retain.
40 ///
41 /// Returns: A JSString that is the same as string.
42 #[cfg(feature = "JSBase")]
43 pub fn JSStringRetain(string: JSStringRef) -> JSStringRef;
44}
45
46extern "C-unwind" {
47 /// Releases a JavaScript string.
48 ///
49 /// Parameter `string`: The JSString to release.
50 #[cfg(feature = "JSBase")]
51 pub fn JSStringRelease(string: JSStringRef);
52}
53
54extern "C-unwind" {
55 /// Returns the number of Unicode characters in a JavaScript string.
56 ///
57 /// Parameter `string`: The JSString whose length (in Unicode characters) you want to know.
58 ///
59 /// Returns: The number of Unicode characters stored in string.
60 #[cfg(feature = "JSBase")]
61 pub fn JSStringGetLength(string: JSStringRef) -> usize;
62}
63
64extern "C-unwind" {
65 /// Returns a pointer to the Unicode character buffer that
66 /// serves as the backing store for a JavaScript string.
67 ///
68 /// Parameter `string`: The JSString whose backing store you want to access.
69 ///
70 /// Returns: A pointer to the Unicode character buffer that serves as string's
71 /// backing store, which will be deallocated when string is deallocated.
72 #[cfg(feature = "JSBase")]
73 pub fn JSStringGetCharactersPtr(string: JSStringRef) -> *const JSChar;
74}
75
76extern "C-unwind" {
77 /// Returns the maximum number of bytes a JavaScript string will
78 /// take up if converted into a null-terminated UTF8 string.
79 ///
80 /// Parameter `string`: The JSString whose maximum converted size (in bytes) you
81 /// want to know.
82 ///
83 /// Returns: The maximum number of bytes that could be required to convert string into a
84 /// null-terminated UTF8 string. The number of bytes that the conversion actually ends
85 /// up requiring could be less than this, but never more.
86 #[cfg(feature = "JSBase")]
87 pub fn JSStringGetMaximumUTF8CStringSize(string: JSStringRef) -> usize;
88}
89
90extern "C-unwind" {
91 /// Converts a JavaScript string into a null-terminated UTF8 string,
92 /// and copies the result into an external byte buffer.
93 ///
94 /// Parameter `string`: The source JSString.
95 ///
96 /// Parameter `buffer`: The destination byte buffer into which to copy a null-terminated
97 /// UTF8 representation of string. On return, buffer contains a UTF8 string
98 /// representation of string. If bufferSize is too small, buffer will contain only
99 /// partial results. If buffer is not at least bufferSize bytes in size,
100 /// behavior is undefined.
101 ///
102 /// Parameter `bufferSize`: The size of the external buffer in bytes.
103 ///
104 /// Returns: The number of bytes written into buffer (including the null-terminator byte).
105 #[cfg(feature = "JSBase")]
106 pub fn JSStringGetUTF8CString(
107 string: JSStringRef,
108 buffer: *mut c_char,
109 buffer_size: usize,
110 ) -> usize;
111}
112
113extern "C-unwind" {
114 /// Tests whether two JavaScript strings match.
115 ///
116 /// Parameter `a`: The first JSString to test.
117 ///
118 /// Parameter `b`: The second JSString to test.
119 ///
120 /// Returns: true if the two strings match, otherwise false.
121 #[cfg(feature = "JSBase")]
122 pub fn JSStringIsEqual(a: JSStringRef, b: JSStringRef) -> bool;
123}
124
125extern "C-unwind" {
126 /// Tests whether a JavaScript string matches a null-terminated UTF8 string.
127 ///
128 /// Parameter `a`: The JSString to test.
129 ///
130 /// Parameter `b`: The null-terminated UTF8 string to test.
131 ///
132 /// Returns: true if the two strings match, otherwise false.
133 #[cfg(feature = "JSBase")]
134 pub fn JSStringIsEqualToUTF8CString(a: JSStringRef, b: *const c_char) -> bool;
135}