Lines 46-58
Link Here
|
46 |
static final int FIXES_LENGTH = PREFIX_LENGTH + SUFFIX_LENGTH; |
46 |
static final int FIXES_LENGTH = PREFIX_LENGTH + SUFFIX_LENGTH; |
47 |
static final int[] EMPTY_INT_ARRAY = new int[0]; |
47 |
static final int[] EMPTY_INT_ARRAY = new int[0]; |
48 |
static final STextEnvironment IGNORE_ENVIRONMENT = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE); |
48 |
static final STextEnvironment IGNORE_ENVIRONMENT = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE); |
49 |
static final int STATE_INITIAL = 0; |
|
|
50 |
|
49 |
|
51 |
protected STextTypeHandler structuredTextHandler; |
50 |
protected STextTypeHandler structuredTextHandler; |
52 |
protected STextEnvironment environment; |
51 |
protected STextEnvironment environment; |
53 |
protected int[] state; |
52 |
protected Object state; |
54 |
|
53 |
|
55 |
public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, int[] state) { |
54 |
public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, Object state) { |
56 |
this.structuredTextHandler = structuredTextHandler; |
55 |
this.structuredTextHandler = structuredTextHandler; |
57 |
this.environment = environment; |
56 |
this.environment = environment; |
58 |
this.state = state; |
57 |
this.state = state; |
Lines 87-106
Link Here
|
87 |
} |
86 |
} |
88 |
|
87 |
|
89 |
public void resetState() { |
88 |
public void resetState() { |
90 |
state[0] = STATE_INITIAL; |
89 |
STextState.setValue(state, null); |
91 |
} |
90 |
} |
92 |
|
91 |
|
93 |
public void setState(int newState) { |
92 |
public void setState(Object newState) { |
94 |
state[0] = newState; |
93 |
STextState.setValue(state, newState); |
95 |
} |
94 |
} |
96 |
|
95 |
|
97 |
public static void setState(int[] state, int newState) { |
96 |
public static void setState(Object state, Object newState) { |
98 |
if (state != null) |
97 |
STextState.setValue(state, newState); |
99 |
state[0] = newState; |
|
|
100 |
} |
98 |
} |
101 |
|
99 |
|
102 |
public int getState() { |
100 |
public Object getState() { |
103 |
return state[0]; |
101 |
Object value = STextState.getValueAndReset(state); |
|
|
102 |
STextState.setValue(state, value); |
103 |
return value; |
104 |
} |
104 |
} |
105 |
|
105 |
|
106 |
static long computeNextLocation(STextTypeHandler handler, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) { |
106 |
static long computeNextLocation(STextTypeHandler handler, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) { |
Lines 243-249
Link Here
|
243 |
* <p> |
243 |
* <p> |
244 |
* @see ISTextExpert#leanToFullText STextEngine.leanToFullText |
244 |
* @see ISTextExpert#leanToFullText STextEngine.leanToFullText |
245 |
*/ |
245 |
*/ |
246 |
public static String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { |
246 |
public static String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { |
247 |
int len = text.length(); |
247 |
int len = text.length(); |
248 |
if (len == 0) |
248 |
if (len == 0) |
249 |
return text; |
249 |
return text; |
Lines 290-296
Link Here
|
290 |
return new String(fullChars); |
290 |
return new String(fullChars); |
291 |
} |
291 |
} |
292 |
|
292 |
|
293 |
public static int[] leanToFullMap(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { |
293 |
public static int[] leanToFullMap(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { |
294 |
int len = text.length(); |
294 |
int len = text.length(); |
295 |
if (len == 0) |
295 |
if (len == 0) |
296 |
return EMPTY_INT_ARRAY; |
296 |
return EMPTY_INT_ARRAY; |
Lines 310-316
Link Here
|
310 |
return map; |
310 |
return map; |
311 |
} |
311 |
} |
312 |
|
312 |
|
313 |
public static int[] leanBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { |
313 |
public static int[] leanBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { |
314 |
int len = text.length(); |
314 |
int len = text.length(); |
315 |
if (len == 0) |
315 |
if (len == 0) |
316 |
return EMPTY_INT_ARRAY; |
316 |
return EMPTY_INT_ARRAY; |
Lines 319-325
Link Here
|
319 |
return offsets.getArray(); |
319 |
return offsets.getArray(); |
320 |
} |
320 |
} |
321 |
|
321 |
|
322 |
static STextOffsets leanToFullCommon(STextTypeHandler handler, STextEnvironment environment, String text, int[] state, STextCharTypes charTypes) { |
322 |
static STextOffsets leanToFullCommon(STextTypeHandler handler, STextEnvironment environment, String text, Object state, STextCharTypes charTypes) { |
323 |
if (environment == null) |
323 |
if (environment == null) |
324 |
environment = STextEnvironment.DEFAULT; |
324 |
environment = STextEnvironment.DEFAULT; |
325 |
int len = text.length(); |
325 |
int len = text.length(); |
Lines 334-344
Link Here
|
334 |
} |
334 |
} |
335 |
// current position |
335 |
// current position |
336 |
int curPos = 0; |
336 |
int curPos = 0; |
337 |
if (state != null && state[0] > STATE_INITIAL) { |
337 |
Object value; |
|
|
338 |
if (state != null && (value = STextState.getValueAndReset(state)) != null) { |
339 |
STextState.setValue(state, value); // restore the value |
338 |
offsets.ensureRoom(); |
340 |
offsets.ensureRoom(); |
339 |
int initState = state[0]; |
341 |
curPos = handler.processSpecial(environment, text, charTypes, offsets, state, 0, -1); |
340 |
state[0] = STATE_INITIAL; |
|
|
341 |
curPos = handler.processSpecial(environment, text, charTypes, offsets, state, initState, -1); |
342 |
} |
342 |
} |
343 |
while (true) { |
343 |
while (true) { |
344 |
// location of next token to handle |
344 |
// location of next token to handle |
Lines 379-385
Link Here
|
379 |
return offsets; |
379 |
return offsets; |
380 |
} |
380 |
} |
381 |
|
381 |
|
382 |
public static String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) { |
382 |
public static String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) { |
383 |
if (text.length() == 0) |
383 |
if (text.length() == 0) |
384 |
return text; |
384 |
return text; |
385 |
if (environment == null) |
385 |
if (environment == null) |
Lines 467-473
Link Here
|
467 |
return lean; |
467 |
return lean; |
468 |
} |
468 |
} |
469 |
|
469 |
|
470 |
public static int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, int[] state) { |
470 |
public static int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { |
471 |
int lenFull = full.length(); |
471 |
int lenFull = full.length(); |
472 |
if (lenFull == 0) |
472 |
if (lenFull == 0) |
473 |
return EMPTY_INT_ARRAY; |
473 |
return EMPTY_INT_ARRAY; |
Lines 498-504
Link Here
|
498 |
return map; |
498 |
return map; |
499 |
} |
499 |
} |
500 |
|
500 |
|
501 |
public static int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, int[] state) { |
501 |
public static int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, Object state) { |
502 |
int lenFull = full.length(); |
502 |
int lenFull = full.length(); |
503 |
if (lenFull == 0) |
503 |
if (lenFull == 0) |
504 |
return EMPTY_INT_ARRAY; |
504 |
return EMPTY_INT_ARRAY; |