1 /*
2  * Copyright (C) 2018 Muhammad Tayyab Akram
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _SB_PUBLIC_SCRIPT_LOCATOR_H
18 #define _SB_PUBLIC_SCRIPT_LOCATOR_H
19 
20 #include "SBBase.h"
21 #include "SBCodepointSequence.h"
22 #include "SBScript.h"
23 
24 typedef struct _SBScriptLocator *SBScriptLocatorRef;
25 
26 /**
27  * A structure containing the information about a run of code points having same script.
28  */
29 typedef struct _SBScriptAgent {
30     SBUInteger offset; /**< The index to the first code unit of the run in source string. */
31     SBUInteger length; /**< The number of code units covering the length of the run. */
32     SBScript script;   /**< The script of the run. */
33 } SBScriptAgent;
34 
35 /**
36  * Creates a script locator object which can be used to find script runs in a string.
37  *
38  * @return
39  *      A reference to a script locator object.
40  */
41 SBScriptLocatorRef SBScriptLocatorCreate(void);
42 
43 /**
44  * Loads a code point sequence in the locator so that its script runs can be located.
45  *
46  * @param locator
47  *      The locator in which the code point sequence will be loaded.
48  * @param codepointSequence
49  *      The code point sequence which will be loaded in the locator.
50  */
51 void SBScriptLocatorLoadCodepoints(SBScriptLocatorRef locator, const SBCodepointSequence *codepointSequence);
52 
53 /**
54  * Returns the agent containing the information of current located script run.
55  *
56  * @param locator
57  *      The locator whose agent is returned.
58  */
59 const SBScriptAgent *SBScriptLocatorGetAgent(SBScriptLocatorRef locator);
60 
61 /**
62  * Instructs the locator to find next script run in the loaded code point sequence.
63  *
64  * @param locator
65  *      The locator whom you want to instruct.
66  * @return
67  *      SBTrue if another script run is available, SBFalse otherwise.
68  * @note
69  *      The locator will be reset after locating last script run.
70  */
71 SBBoolean SBScriptLocatorMoveNext(SBScriptLocatorRef locator);
72 
73 /**
74  * Instructs the locator to reset itself so that script runs of the loaded line can be obatained
75  * from the beginning.
76  *
77  * @param locator
78  *      The locator whom you want to reset.
79  */
80 void SBScriptLocatorReset(SBScriptLocatorRef locator);
81 
82 /**
83  * Increments the reference count of a script locator object.
84  *
85  * @param locator
86  *      The script locator object whose reference count will be incremented.
87  * @return
88  *      The same script locator object passed in as the parameter.
89  */
90 SBScriptLocatorRef SBScriptLocatorRetain(SBScriptLocatorRef locator);
91 
92 /**
93  * Decrements the reference count of a script locator object. The object will be deallocated when
94  * its reference count reaches zero.
95  *
96  * @param locator
97  *      The script locator object whose reference count will be decremented.
98  */
99 void SBScriptLocatorRelease(SBScriptLocatorRef locator);
100 
101 #endif
102