objc2_core_foundation/generated/CFStringTokenizer.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12impl CFStringTokenizer {
13 /// Guesses the language of a string and returns the BCP 47 string of the
14 /// language.
15 ///
16 /// Parameter `string`: The string whose language is to be guessed.
17 ///
18 /// Parameter `range`: The range of characters in string whose language to be
19 /// guessed. The specified range must not exceed the bounds of the string.
20 ///
21 /// Returns: A language represented in BCP 47 string. NULL is returned either if
22 /// string is NULL, the location of range is negative, the length of range
23 /// is 0, or the language of the string cannot be guessed.
24 ///
25 /// The result is not guaranteed to be accurate. Typically 200-400
26 /// characters are required to reliably guess the language of a string.
27 #[doc(alias = "CFStringTokenizerCopyBestStringLanguage")]
28 #[inline]
29 pub unsafe fn best_string_language(
30 string: &CFString,
31 range: CFRange,
32 ) -> Option<CFRetained<CFString>> {
33 extern "C-unwind" {
34 fn CFStringTokenizerCopyBestStringLanguage(
35 string: &CFString,
36 range: CFRange,
37 ) -> Option<NonNull<CFString>>;
38 }
39 let ret = unsafe { CFStringTokenizerCopyBestStringLanguage(string, range) };
40 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
41 }
42}
43
44/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfstringtokenizer?language=objc)
45#[repr(C)]
46pub struct CFStringTokenizer {
47 inner: [u8; 0],
48 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
49}
50
51cf_type!(
52 unsafe impl CFStringTokenizer {}
53);
54#[cfg(feature = "objc2")]
55cf_objc2_type!(
56 unsafe impl RefEncode<"__CFStringTokenizer"> for CFStringTokenizer {}
57);
58
59/// Tokenization Unit
60/// Use one of tokenization unit options with CFStringTokenizerCreate to
61/// specify how the string should be tokenized.
62///
63/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitword?language=objc)
64pub const kCFStringTokenizerUnitWord: CFOptionFlags = 0;
65/// Tokenization Unit
66/// Use one of tokenization unit options with CFStringTokenizerCreate to
67/// specify how the string should be tokenized.
68///
69/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitsentence?language=objc)
70pub const kCFStringTokenizerUnitSentence: CFOptionFlags = 1;
71/// Tokenization Unit
72/// Use one of tokenization unit options with CFStringTokenizerCreate to
73/// specify how the string should be tokenized.
74///
75/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitparagraph?language=objc)
76pub const kCFStringTokenizerUnitParagraph: CFOptionFlags = 2;
77/// Tokenization Unit
78/// Use one of tokenization unit options with CFStringTokenizerCreate to
79/// specify how the string should be tokenized.
80///
81/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitlinebreak?language=objc)
82pub const kCFStringTokenizerUnitLineBreak: CFOptionFlags = 3;
83/// Tokenization Unit
84/// Use one of tokenization unit options with CFStringTokenizerCreate to
85/// specify how the string should be tokenized.
86///
87/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerunitwordboundary?language=objc)
88pub const kCFStringTokenizerUnitWordBoundary: CFOptionFlags = 4;
89/// Attribute Specifier
90/// Use attribute specifier to tell tokenizer to prepare the specified attribute
91/// when it tokenizes the given string. The attribute value can be retrieved by
92/// calling CFStringTokenizerCopyCurrentTokenAttribute with one of the attribute
93/// option.
94///
95/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerattributelatintranscription?language=objc)
96pub const kCFStringTokenizerAttributeLatinTranscription: CFOptionFlags = 1 << 16;
97/// Attribute Specifier
98/// Use attribute specifier to tell tokenizer to prepare the specified attribute
99/// when it tokenizes the given string. The attribute value can be retrieved by
100/// calling CFStringTokenizerCopyCurrentTokenAttribute with one of the attribute
101/// option.
102///
103/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfstringtokenizerattributelanguage?language=objc)
104pub const kCFStringTokenizerAttributeLanguage: CFOptionFlags = 1 << 17;
105
106/// Token type
107/// CFStringTokenizerGoToTokenAtIndex / CFStringTokenizerAdvanceToNextToken returns
108/// the type of current token.
109///
110/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfstringtokenizertokentype?language=objc)
111// NS_OPTIONS
112#[repr(transparent)]
113#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
114pub struct CFStringTokenizerTokenType(pub CFOptionFlags);
115bitflags::bitflags! {
116 impl CFStringTokenizerTokenType: CFOptionFlags {
117 #[doc(alias = "kCFStringTokenizerTokenNone")]
118 const None = 0;
119 #[doc(alias = "kCFStringTokenizerTokenNormal")]
120 const Normal = 1<<0;
121/// Compound token which may contain subtokens but with no derived subtokens.
122/// Its subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens.
123 #[doc(alias = "kCFStringTokenizerTokenHasSubTokensMask")]
124 const HasSubTokensMask = 1<<1;
125/// Compound token which may contain derived subtokens.
126/// Its subtokens and derived subtokens can be obtained by calling
127/// CFStringTokenizerGetCurrentSubTokens.
128 #[doc(alias = "kCFStringTokenizerTokenHasDerivedSubTokensMask")]
129 const HasDerivedSubTokensMask = 1<<2;
130/// Compound token which may contain derived subtokens.
131/// Its subtokens and derived subtokens can be obtained by calling
132/// CFStringTokenizerGetCurrentSubTokens.
133 #[doc(alias = "kCFStringTokenizerTokenHasHasNumbersMask")]
134 const HasHasNumbersMask = 1<<3;
135/// Compound token which may contain derived subtokens.
136/// Its subtokens and derived subtokens can be obtained by calling
137/// CFStringTokenizerGetCurrentSubTokens.
138 #[doc(alias = "kCFStringTokenizerTokenHasNonLettersMask")]
139 const HasNonLettersMask = 1<<4;
140/// Compound token which may contain derived subtokens.
141/// Its subtokens and derived subtokens can be obtained by calling
142/// CFStringTokenizerGetCurrentSubTokens.
143 #[doc(alias = "kCFStringTokenizerTokenIsCJWordMask")]
144 const IsCJWordMask = 1<<5;
145 }
146}
147
148#[cfg(feature = "objc2")]
149unsafe impl Encode for CFStringTokenizerTokenType {
150 const ENCODING: Encoding = CFOptionFlags::ENCODING;
151}
152
153#[cfg(feature = "objc2")]
154unsafe impl RefEncode for CFStringTokenizerTokenType {
155 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
156}
157
158unsafe impl ConcreteType for CFStringTokenizer {
159 /// Get the type identifier.
160 ///
161 /// Returns: the type identifier of all CFStringTokenizer instances.
162 #[doc(alias = "CFStringTokenizerGetTypeID")]
163 #[inline]
164 fn type_id() -> CFTypeID {
165 extern "C-unwind" {
166 fn CFStringTokenizerGetTypeID() -> CFTypeID;
167 }
168 unsafe { CFStringTokenizerGetTypeID() }
169 }
170}
171
172impl CFStringTokenizer {
173 /// Creates a tokenizer instance.
174 ///
175 /// Parameter `alloc`: The CFAllocator which should be used to allocate memory for the
176 /// tokenizer and its storage for values. This parameter may be NULL in which
177 /// case the current default CFAllocator is used.
178 ///
179 /// Parameter `string`: The string to tokenize.
180 ///
181 /// Parameter `range`: The range of characters within the string to be tokenized. The
182 /// specified range must not exceed the length of the string.
183 ///
184 /// Parameter `options`: Use one of the Tokenization Unit options to specify how the
185 /// string should be tokenized. Optionally specify one or more attribute
186 /// specifiers to tell the tokenizer to prepare specified attributes when it
187 /// tokenizes the string.
188 ///
189 /// Parameter `locale`: The locale to specify language or region specific behavior. Pass
190 /// NULL if you want tokenizer to identify the locale automatically.
191 ///
192 /// Returns: A reference to the new CFStringTokenizer.
193 #[doc(alias = "CFStringTokenizerCreate")]
194 #[cfg(feature = "CFLocale")]
195 #[inline]
196 pub unsafe fn new(
197 alloc: Option<&CFAllocator>,
198 string: Option<&CFString>,
199 range: CFRange,
200 options: CFOptionFlags,
201 locale: Option<&CFLocale>,
202 ) -> Option<CFRetained<CFStringTokenizer>> {
203 extern "C-unwind" {
204 fn CFStringTokenizerCreate(
205 alloc: Option<&CFAllocator>,
206 string: Option<&CFString>,
207 range: CFRange,
208 options: CFOptionFlags,
209 locale: Option<&CFLocale>,
210 ) -> Option<NonNull<CFStringTokenizer>>;
211 }
212 let ret = unsafe { CFStringTokenizerCreate(alloc, string, range, options, locale) };
213 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
214 }
215
216 /// Set the string to tokenize.
217 ///
218 /// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
219 /// CFStringTokenizerCreate.
220 ///
221 /// Parameter `string`: The string to tokenize.
222 ///
223 /// Parameter `range`: The range of characters within the string to be tokenized. The
224 /// specified range must not exceed the length of the string.
225 #[doc(alias = "CFStringTokenizerSetString")]
226 #[inline]
227 pub unsafe fn set_string(self: &CFStringTokenizer, string: Option<&CFString>, range: CFRange) {
228 extern "C-unwind" {
229 fn CFStringTokenizerSetString(
230 tokenizer: &CFStringTokenizer,
231 string: Option<&CFString>,
232 range: CFRange,
233 );
234 }
235 unsafe { CFStringTokenizerSetString(self, string, range) }
236 }
237
238 /// Random access to a token. Find a token that includes the character specified
239 /// by character index, and set it as the current token.
240 ///
241 /// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
242 /// CFStringTokenizerCreate.
243 ///
244 /// Parameter `index`: The index of the Unicode character in the CFString.
245 ///
246 /// Returns: Type of the token if succeeded in finding a token and setting it as
247 /// current token. kCFStringTokenizerTokenNone if failed in finding a token.
248 ///
249 /// The range and attribute of the token can be obtained by calling
250 /// CFStringTokenizerGetCurrentTokenRange and CFStringTokenizerCopyCurrentTokenAttribute.
251 /// If the token is a compound (with type kCFStringTokenizerTokenHasSubTokensMask or
252 /// kCFStringTokenizerTokenHasDerivedSubTokensMask), its subtokens and
253 /// (or) derived subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens.
254 #[doc(alias = "CFStringTokenizerGoToTokenAtIndex")]
255 #[inline]
256 pub unsafe fn go_to_token_at_index(
257 self: &CFStringTokenizer,
258 index: CFIndex,
259 ) -> CFStringTokenizerTokenType {
260 extern "C-unwind" {
261 fn CFStringTokenizerGoToTokenAtIndex(
262 tokenizer: &CFStringTokenizer,
263 index: CFIndex,
264 ) -> CFStringTokenizerTokenType;
265 }
266 unsafe { CFStringTokenizerGoToTokenAtIndex(self, index) }
267 }
268
269 /// Token enumerator.
270 ///
271 /// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
272 /// CFStringTokenizerCreate.
273 ///
274 /// Returns: Type of the token if succeeded in finding a token and setting it as
275 /// current token. kCFStringTokenizerTokenNone if failed in finding a token.
276 ///
277 /// If there is no preceding call to CFStringTokenizerGoToTokenAtIndex
278 /// or CFStringTokenizerAdvanceToNextToken, it finds the first token in the range
279 /// specified to CFStringTokenizerCreate. If there is a current token after successful
280 /// call to CFStringTokenizerGoToTokenAtIndex or CFStringTokenizerAdvanceToNextToken,
281 /// it proceeds to the next token. If succeeded in finding a token, set it as current
282 /// token and return its token type. Otherwise invalidate current token and return
283 /// kCFStringTokenizerTokenNone.
284 /// The range and attribute of the token can be obtained by calling
285 /// CFStringTokenizerGetCurrentTokenRange and
286 /// CFStringTokenizerCopyCurrentTokenAttribute. If the token is a compound
287 /// (with type kCFStringTokenizerTokenHasSubTokensMask or
288 /// kCFStringTokenizerTokenHasDerivedSubTokensMask), its subtokens and
289 /// (or) derived subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens.
290 #[doc(alias = "CFStringTokenizerAdvanceToNextToken")]
291 #[inline]
292 pub unsafe fn advance_to_next_token(self: &CFStringTokenizer) -> CFStringTokenizerTokenType {
293 extern "C-unwind" {
294 fn CFStringTokenizerAdvanceToNextToken(
295 tokenizer: &CFStringTokenizer,
296 ) -> CFStringTokenizerTokenType;
297 }
298 unsafe { CFStringTokenizerAdvanceToNextToken(self) }
299 }
300
301 /// Returns the range of current token.
302 ///
303 /// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
304 /// CFStringTokenizerCreate.
305 ///
306 /// Returns: Range of current token, or {kCFNotFound,0} if there is no current token.
307 #[doc(alias = "CFStringTokenizerGetCurrentTokenRange")]
308 #[inline]
309 pub unsafe fn current_token_range(self: &CFStringTokenizer) -> CFRange {
310 extern "C-unwind" {
311 fn CFStringTokenizerGetCurrentTokenRange(tokenizer: &CFStringTokenizer) -> CFRange;
312 }
313 unsafe { CFStringTokenizerGetCurrentTokenRange(self) }
314 }
315
316 /// Copies the specified attribute of current token.
317 ///
318 /// Parameter `tokenizer`: The reference to CFStringTokenizer returned by
319 /// CFStringTokenizerCreate.
320 ///
321 /// Parameter `attribute`: Specify a token attribute you want to obtain. The value is
322 /// one of kCFStringTokenizerAttributeLatinTranscription or
323 /// kCFStringTokenizerAttributeLanguage.
324 ///
325 /// Returns: Token attribute, or NULL if current token does not have the specified
326 /// attribute or if there is no current token.
327 #[doc(alias = "CFStringTokenizerCopyCurrentTokenAttribute")]
328 #[inline]
329 pub unsafe fn current_token_attribute(
330 self: &CFStringTokenizer,
331 attribute: CFOptionFlags,
332 ) -> Option<CFRetained<CFType>> {
333 extern "C-unwind" {
334 fn CFStringTokenizerCopyCurrentTokenAttribute(
335 tokenizer: &CFStringTokenizer,
336 attribute: CFOptionFlags,
337 ) -> Option<NonNull<CFType>>;
338 }
339 let ret = unsafe { CFStringTokenizerCopyCurrentTokenAttribute(self, attribute) };
340 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
341 }
342
343 /// Retrieves the subtokens or derived subtokens contained in the compound token.
344 ///
345 /// Parameter `tokenizer`: The reference to CFStringTokenizer returned by CFStringTokenizerCreate.
346 ///
347 /// Parameter `ranges`: An array of CFRange to fill in with the ranges of subtokens. The filled in
348 /// ranges are relative to the string specified to CFStringTokenizerCreate. This parameter
349 /// can be NULL.
350 ///
351 /// Parameter `maxRangeLength`: The maximum number of ranges to return.
352 ///
353 /// Parameter `derivedSubTokens`: An array of CFMutableArray to which the derived subtokens are to
354 /// be added. This parameter can be NULL.
355 ///
356 /// Returns: number of subtokens.
357 ///
358 /// If token type is kCFStringTokenizerTokenNone, the ranges array and
359 /// derivedSubTokens array are untouched and the return value is 0.
360 /// If token type is kCFStringTokenizerTokenNormal, the ranges array has one item
361 /// filled in with the entire range of the token (if maxRangeLength >= 1) and a string
362 /// taken from the entire token range is added to the derivedSubTokens array and the
363 /// return value is 1.
364 /// If token type is kCFStringTokenizerTokenHasSubTokensMask or
365 /// kCFStringTokenizerTokenHasDerivedSubTokensMask, the ranges array is filled
366 /// in with as many items as there are subtokens (up to a limit of maxRangeLength).
367 /// The derivedSubTokens array will have sub tokens added even when the sub token is a
368 /// substring of the token. If token type is kCFStringTokenizerTokenHasSubTokensMask,
369 /// the ordinary non-derived subtokens are added to the derivedSubTokens array.
370 #[doc(alias = "CFStringTokenizerGetCurrentSubTokens")]
371 #[cfg(feature = "CFArray")]
372 #[inline]
373 pub unsafe fn current_sub_tokens(
374 self: &CFStringTokenizer,
375 ranges: *mut CFRange,
376 max_range_length: CFIndex,
377 derived_sub_tokens: Option<&CFMutableArray>,
378 ) -> CFIndex {
379 extern "C-unwind" {
380 fn CFStringTokenizerGetCurrentSubTokens(
381 tokenizer: &CFStringTokenizer,
382 ranges: *mut CFRange,
383 max_range_length: CFIndex,
384 derived_sub_tokens: Option<&CFMutableArray>,
385 ) -> CFIndex;
386 }
387 unsafe {
388 CFStringTokenizerGetCurrentSubTokens(self, ranges, max_range_length, derived_sub_tokens)
389 }
390 }
391}
392
393#[deprecated = "renamed to `CFStringTokenizer::best_string_language`"]
394#[inline]
395pub unsafe extern "C-unwind" fn CFStringTokenizerCopyBestStringLanguage(
396 string: &CFString,
397 range: CFRange,
398) -> Option<CFRetained<CFString>> {
399 extern "C-unwind" {
400 fn CFStringTokenizerCopyBestStringLanguage(
401 string: &CFString,
402 range: CFRange,
403 ) -> Option<NonNull<CFString>>;
404 }
405 let ret = unsafe { CFStringTokenizerCopyBestStringLanguage(string, range) };
406 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
407}
408
409#[cfg(feature = "CFLocale")]
410#[deprecated = "renamed to `CFStringTokenizer::new`"]
411#[inline]
412pub unsafe extern "C-unwind" fn CFStringTokenizerCreate(
413 alloc: Option<&CFAllocator>,
414 string: Option<&CFString>,
415 range: CFRange,
416 options: CFOptionFlags,
417 locale: Option<&CFLocale>,
418) -> Option<CFRetained<CFStringTokenizer>> {
419 extern "C-unwind" {
420 fn CFStringTokenizerCreate(
421 alloc: Option<&CFAllocator>,
422 string: Option<&CFString>,
423 range: CFRange,
424 options: CFOptionFlags,
425 locale: Option<&CFLocale>,
426 ) -> Option<NonNull<CFStringTokenizer>>;
427 }
428 let ret = unsafe { CFStringTokenizerCreate(alloc, string, range, options, locale) };
429 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
430}
431
432extern "C-unwind" {
433 #[deprecated = "renamed to `CFStringTokenizer::set_string`"]
434 pub fn CFStringTokenizerSetString(
435 tokenizer: &CFStringTokenizer,
436 string: Option<&CFString>,
437 range: CFRange,
438 );
439}
440
441extern "C-unwind" {
442 #[deprecated = "renamed to `CFStringTokenizer::go_to_token_at_index`"]
443 pub fn CFStringTokenizerGoToTokenAtIndex(
444 tokenizer: &CFStringTokenizer,
445 index: CFIndex,
446 ) -> CFStringTokenizerTokenType;
447}
448
449extern "C-unwind" {
450 #[deprecated = "renamed to `CFStringTokenizer::advance_to_next_token`"]
451 pub fn CFStringTokenizerAdvanceToNextToken(
452 tokenizer: &CFStringTokenizer,
453 ) -> CFStringTokenizerTokenType;
454}
455
456extern "C-unwind" {
457 #[deprecated = "renamed to `CFStringTokenizer::current_token_range`"]
458 pub fn CFStringTokenizerGetCurrentTokenRange(tokenizer: &CFStringTokenizer) -> CFRange;
459}
460
461#[deprecated = "renamed to `CFStringTokenizer::current_token_attribute`"]
462#[inline]
463pub unsafe extern "C-unwind" fn CFStringTokenizerCopyCurrentTokenAttribute(
464 tokenizer: &CFStringTokenizer,
465 attribute: CFOptionFlags,
466) -> Option<CFRetained<CFType>> {
467 extern "C-unwind" {
468 fn CFStringTokenizerCopyCurrentTokenAttribute(
469 tokenizer: &CFStringTokenizer,
470 attribute: CFOptionFlags,
471 ) -> Option<NonNull<CFType>>;
472 }
473 let ret = unsafe { CFStringTokenizerCopyCurrentTokenAttribute(tokenizer, attribute) };
474 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
475}
476
477extern "C-unwind" {
478 #[cfg(feature = "CFArray")]
479 #[deprecated = "renamed to `CFStringTokenizer::current_sub_tokens`"]
480 pub fn CFStringTokenizerGetCurrentSubTokens(
481 tokenizer: &CFStringTokenizer,
482 ranges: *mut CFRange,
483 max_range_length: CFIndex,
484 derived_sub_tokens: Option<&CFMutableArray>,
485 ) -> CFIndex;
486}