Skip to content

Commit df5babe

Browse files
small perfromacne improve for string analyse utils, finilizing mvn 1.3.8
1 parent 22e0c60 commit df5babe

File tree

12 files changed

+193
-135
lines changed

12 files changed

+193
-135
lines changed

SerialX-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>org.ugp.serialx</groupId>
1010
<artifactId>core</artifactId>
11-
<version>1.3.7</version>
11+
<version>1.3.8</version>
1212

1313
<name>SerialX core</name>
1414
<description>Core of SerialX. Contains core features and utilities shared across the library.</description>

SerialX-core/src/main/java/org/ugp/serialx/Utils.java

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ public static StringBuilder multilpy(CharSequence str, int times)
466466
* @param s | String to split and check some syntax.
467467
* @param splitter | Chars where string will be split!
468468
*
469-
* @return String splitted after splitters. More than one splitter in row will be take as 1. Each resulting token will be {@link String#trim() trim}<code>med</code>!
469+
* @return String splitted after splitters. More than one splitter in row will be take as 1. Each resulting token will be {@link String#trim() trim}<code>med</code>!<br>
470+
* Note: Splitting will only occur if splitter is not in object meaning it is not in string nor between '{' or '[' and ']' or '}
470471
*
471472
* @since 1.0.0
472473
*/
@@ -483,7 +484,8 @@ public static String[] splitValues(String s, char... splitter)
483484
* <b>If 2</b>, splitting will occur after any number of splitters, n number of splitters in row will be treated as 1!
484485
* @param splitter | Chars where string will be split!
485486
*
486-
* @return String splitted after splitters according to arguments. Each resulting token will be {@link String#trim() trim}<code>med</code>!
487+
* @return String splitted after splitters according to arguments. Each resulting token will be {@link String#trim() trim}<code>med</code>!<br>
488+
* Note: Splitting will only occur if splitter is not in object meaning it is not in string nor between '{' or '[' and ']' or '}'
487489
*
488490
* @since 1.3.0
489491
*/
@@ -501,7 +503,8 @@ public static String[] splitValues(String s, int limit, int splittingStrategy, c
501503
* @param splitBreaks | When some of these characters is encountered, splitting is terminated for the rest of the string!
502504
* @param splitter | Chars where string will be split!
503505
*
504-
* @return String splitted after splitters according to arguments. Each resulting token will be {@link String#trim() trim}<code>med</code>!
506+
* @return String splitted after splitters according to arguments. Each resulting token will be {@link String#trim() trim}<code>med</code>!<br>
507+
* Note: Splitting will only occur if splitter is not in object meaning it is not in string nor between '{' or '[' and ']' or '}'
505508
*
506509
* @since 1.3.5
507510
*/
@@ -517,10 +520,11 @@ public static String[] splitValues(String s, int limit, int splittingStrategy, c
517520
* @param splittingStrategy | <b>If 0</b>, splitting will occur after each splitter!
518521
* <b>If 1</b>, string will be splitted after only one splitter, more than one splitters in row will be ignored!
519522
* <b>If 2</b>, splitting will occur after any number of splitters, n number of splitters in row will be treated as 1!
520-
* @param splitBreaks | When some of these characters is encountered, splitting is terminated for the rest of the string!
523+
* @param splitBreaks | When some of these characters is encountered (not in object), splitting is terminated for the rest of the string!
521524
* @param splitter | Chars where string will be split!
522525
*
523-
* @return String splitted after splitters according to arguments. Each resulting token will be {@link String#trim() trim}<code>med</code>!
526+
* @return String splitted after splitters according to arguments. Each resulting token will be {@link String#trim() trim}<code>med</code>!<br>
527+
* Note: Splitting will only occur if splitter is not in object meaning it is not in string nor between '{' or '[' and ']' or '}'
524528
*
525529
* @since 1.3.8
526530
*/
@@ -534,51 +538,47 @@ public static String[] splitValues(String s, int i, int limit, int splittingStra
534538

535539
List<String> result = new ArrayList<>();
536540

537-
int brackets = 0, lastIndex = 0, len = s.length();
541+
int lastIndex = 0, len = s.length();
538542
for (int count = 1, oldCh = 0; i < len && (limit <= 0 || count < limit); i++)
539543
{
540-
char ch = s.charAt(i);
544+
int ch = s.charAt(i);
541545
if (ch == '"')
542546
{
543547
do if (++i >= len)
544548
throw new IllegalArgumentException("Unclosed or missing quotes in: " + s);
545549
while (s.charAt(i) != '"');
546550
}
547-
else
551+
else if ((ch | ' ') == '{')
548552
{
549-
if (isOneOf(ch, splitBreaks))
553+
for (int brackets = 1; brackets != 0; )
550554
{
551-
brackets = 0;
552-
break;
553-
}
554-
555-
if (brackets == 0 && isOneOf(ch, splitter) &&
556-
(splittingStrategy != 1 || ch != oldCh && (i >= len-1 || !isOneOf(s.charAt(i+1), splitter))))
557-
{
558-
String tok = s.substring(lastIndex, i).trim();
559-
if (splittingStrategy < 2 || result.isEmpty() || !tok.isEmpty())
560-
{
561-
result.add(tok);
562-
lastIndex = i + 1;
563-
564-
count++;
565-
}
555+
if (++i >= len)
556+
throw new IllegalArgumentException("Missing ("+ brackets + ") closing bracket in: " + s);
557+
if ((ch = (s.charAt(i) | ' ')) == '{')
558+
brackets++;
559+
else if (ch == '}')
560+
brackets--;
561+
else if (ch == '"')
562+
while (++i < len && s.charAt(i) != '"');
566563
}
567-
else if ((ch | ' ') == '{')
568-
brackets++;
569-
else if ((ch | ' ') == '}')
564+
}
565+
else if (isOneOf(ch, splitBreaks))
566+
break;
567+
else if (isOneOf(ch, splitter) &&
568+
(splittingStrategy != 1 || ch != oldCh && (i >= len-1 || !isOneOf(s.charAt(i+1), splitter))))
569+
{
570+
String tok = s.substring(lastIndex, i).trim();
571+
if (splittingStrategy < 2 || result.isEmpty() || !tok.isEmpty())
570572
{
571-
if (brackets > 0)
572-
brackets--;
573-
else
574-
throw new IllegalArgumentException("Missing opening bracket in: " + s);
573+
result.add(tok);
574+
lastIndex = i + 1;
575+
576+
count++;
575577
}
576578
}
579+
577580
oldCh = ch;
578581
}
579-
580-
if (brackets > 0)
581-
throw new IllegalArgumentException("Unclosed brackets in: " + s);
582582

583583
result.add(s.substring(lastIndex, len).trim());
584584
return result.toArray(new String[0]);
@@ -611,26 +611,31 @@ public static int indexOfNotInObj(CharSequence s, char... oneOf)
611611
*/
612612
public static int indexOfNotInObj(CharSequence s, int from, int to, int defaultReturn, boolean firstIndex, char... oneOf)
613613
{
614-
for (int brackets = 0; from < to; from++)
614+
for (; from < to; from++)
615615
{
616-
char ch = s.charAt(from);
616+
int ch = s.charAt(from);
617617
if (ch == '"')
618618
while (++from < to && s.charAt(from) != '"');
619-
else if (brackets == 0 && /*oneOf.length == 0 ? ch == oneOf[0] :*/ isOneOf(ch, oneOf))
619+
else if ((ch | ' ') == '{')
620+
{
621+
for (int brackets = 1; brackets != 0; )
622+
{
623+
if (++from >= to)
624+
throw new IllegalArgumentException("Missing ("+ brackets + ") closing bracket in: " + s);
625+
if ((ch = (s.charAt(from) | ' ')) == '{')
626+
brackets++;
627+
else if (ch == '}')
628+
brackets--;
629+
else if (ch == '"')
630+
while (++from < to && s.charAt(from) != '"');
631+
}
632+
}
633+
else if (isOneOf(ch, oneOf))
620634
{
621635
if (firstIndex)
622636
return from;
623637
defaultReturn = from;
624638
}
625-
else if ((ch | ' ') == '{')
626-
brackets++;
627-
else if ((ch | ' ') == '}')
628-
{
629-
if (brackets > 0)
630-
brackets--;
631-
else
632-
throw new IllegalArgumentException("Missing closing bracket in: " + s);
633-
}
634639
}
635640
return defaultReturn;
636641
}
@@ -665,21 +670,26 @@ public static int indexOfNotInObj(CharSequence s, int from, int to, int defaultR
665670
if (sequencesToFind.length < 1)
666671
return defaultReturn;
667672

668-
for (int brackets = 0; from < to; from++)
673+
for (; from < to; from++)
669674
{
670-
char ch = s.charAt(from);
675+
int ch = s.charAt(from);
671676
if (ch == '"')
672677
while (++from < to && s.charAt(from) != '"');
673678
else if ((ch | ' ') == '{')
674-
brackets++;
675-
else if ((ch | ' ') == '}')
676679
{
677-
if (brackets > 0)
678-
brackets--;
679-
else
680-
throw new IllegalArgumentException("Missing closing bracket in: " + s);
680+
for (int brackets = 1; brackets != 0; )
681+
{
682+
if (++from >= to)
683+
throw new IllegalArgumentException("Missing ("+ brackets + ") closing bracket in: " + s);
684+
if ((ch = (s.charAt(from) | ' ')) == '{')
685+
brackets++;
686+
else if (ch == '}')
687+
brackets--;
688+
else if (ch == '"')
689+
while (++from < to && s.charAt(from) != '"');
690+
}
681691
}
682-
else if (brackets == 0)
692+
else
683693
{
684694
findMatch: for (int cur = 0, seqsLen = sequencesToFind.length; cur < seqsLen; cur++)
685695
{

SerialX-devtools/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>org.ugp.serialx</groupId>
1010
<artifactId>devtools</artifactId>
11-
<version>1.3.7</version>
11+
<version>1.3.8</version>
1212

1313
<name>SerialX devtools</name>
1414
<description>Tools for debugging, mainly for Parser/Converter API. It is intended for DSL developers and people who want to add their own data formats.</description>

SerialX-json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>org.ugp.serialx</groupId>
1010
<artifactId>json</artifactId>
11-
<version>1.3.7</version>
11+
<version>1.3.8</version>
1212

1313
<name>SerialX json</name>
1414
<description>SerialX Json support</description>

SerialX-juss/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>org.ugp.serialx</groupId>
1010
<artifactId>juss</artifactId>
11-
<version>1.3.7</version>
11+
<version>1.3.8</version>
1212

1313
<name>SerialX-juss</name>
1414
<description>SerialX support for Java Universal Serial Script data format, custom default format of SerialX!</description>

SerialX-juss/src/main/java/org/ugp/serialx/juss/JussSerializer.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -596,18 +596,32 @@ protected List<Object> splitAndParse(StringBuilder formattedStr, Object... parse
596596
ParserRegistry reg = getParsers();
597597

598598
//DataParser[] parsers = new DataParser[DataParser.REGISTRY.size()];
599-
int brackets = 0, lastIndex = 0, len = formattedStr.length();
599+
int lastIndex = 0, len = formattedStr.length();
600600
//boolean isBracketSplit = false;
601601
for (int i = 0; i < len; i++)
602602
{
603-
char ch = formattedStr.charAt(i);
603+
int ch = formattedStr.charAt(i);
604604
if (ch == '"')
605605
{
606606
do if (++i >= len)
607607
throw new IllegalArgumentException("Unclosed or missing quotes in: " + formattedStr);
608608
while (formattedStr.charAt(i) != '"');
609609
}
610-
else if (brackets == 0 && (ch == ';' || ch == ',')/* || (brackets == 1 && (isBracketSplit = ch == '}' || ch == ']'))*/)
610+
else if ((ch | ' ') == '{')
611+
{
612+
for (int brackets = 1; brackets != 0; )
613+
{
614+
if (++i >= len)
615+
throw new IllegalArgumentException("Missing ("+ brackets + ") closing bracket in: " + formattedStr);
616+
if ((ch = (formattedStr.charAt(i) | ' ')) == '{')
617+
brackets++;
618+
else if (ch == '}')
619+
brackets--;
620+
else if (ch == '"')
621+
while (++i < len && formattedStr.charAt(i) != '"');
622+
}
623+
}
624+
else if ((ch == ';' || ch == ',')/* || (brackets == 1 && (isBracketSplit = ch == '}' || ch == ']'))*/)
611625
{
612626
String str = formattedStr.substring(lastIndex == 0 ? 0 : lastIndex + 1, lastIndex = i /*+ (isBracketSplit ? 1 : 0)*/).trim();
613627
if (!str.isEmpty())
@@ -618,20 +632,8 @@ protected List<Object> splitAndParse(StringBuilder formattedStr, Object... parse
618632
}
619633
//add = 1;
620634
}
621-
else if ((ch | ' ') == '{')
622-
brackets++;
623-
else if ((ch | ' ') == '}')
624-
{
625-
if (brackets > 0)
626-
brackets--;
627-
else
628-
throw new IllegalArgumentException("Missing opening bracket in: " + formattedStr);
629-
}
630635
}
631636

632-
if (brackets > 0)
633-
throw new IllegalArgumentException("Unclosed brackets in: " + formattedStr);
634-
635637
String str = formattedStr.substring(lastIndex == 0 ? 0 : lastIndex + 1, len).trim();
636638
if (!str.isEmpty())
637639
{

SerialX-juss/src/main/java/org/ugp/serialx/juss/converters/OperationGroups.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,26 @@ public static int isGroupMark(CharSequence s, char groupMark)
127127
*/
128128
public static int indexOfOpening(CharSequence str, int from, char... openings)
129129
{
130-
for (int len = str.length(), brackets = 0; from < len; from++)
130+
for (int len = str.length(); from < len; from++)
131131
{
132-
char ch = str.charAt(from);
132+
int ch = str.charAt(from);
133133
if (ch == '"')
134134
while (++from < len && str.charAt(from) != '"');
135135
else if ((ch | ' ') == '{')
136-
brackets++;
137-
else if ((ch | ' ') == '}')
138136
{
139-
if (brackets > 0)
140-
brackets--;
141-
else
142-
throw new IllegalArgumentException("Missing opening bracket in: " + str);
137+
for (int brackets = 1; brackets != 0; )
138+
{
139+
if (++from >= len)
140+
throw new IllegalArgumentException("Missing ("+ brackets + ") closing bracket in: " + str);
141+
if ((ch = (str.charAt(from) | ' ')) == '{')
142+
brackets++;
143+
else if (ch == '}')
144+
brackets--;
145+
else if (ch == '"')
146+
while (++from < len && str.charAt(from) != '"');
147+
}
143148
}
144-
else if (brackets == 0 && isOneOf(ch, openings))
149+
else if (isOneOf(ch, openings))
145150
return from;
146151
}
147152
return -1;
@@ -159,21 +164,26 @@ else if (brackets == 0 && isOneOf(ch, openings))
159164
*/
160165
public static int indexOfClosing(CharSequence str, int from, char[] openings, char... closing)
161166
{
162-
for (int len = str.length(), brackets = 0, ops = 0; from < len; from++)
167+
for (int len = str.length(), ops = 0; from < len; from++)
163168
{
164-
char ch = str.charAt(from);
169+
int ch = str.charAt(from);
165170
if (ch == '"')
166171
while (++from < len && str.charAt(from) != '"');
167172
else if ((ch | ' ') == '{')
168-
brackets++;
169-
else if ((ch | ' ') == '}')
170173
{
171-
if (brackets > 0)
172-
brackets--;
173-
else
174-
throw new IllegalArgumentException("Missing opening bracket in: " + str);
174+
for (int brackets = 1; brackets != 0; )
175+
{
176+
if (++from >= len)
177+
throw new IllegalArgumentException("Missing ("+ brackets + ") closing bracket in: " + str);
178+
if ((ch = (str.charAt(from) | ' ')) == '{')
179+
brackets++;
180+
else if (ch == '}')
181+
brackets--;
182+
else if (ch == '"')
183+
while (++from < len && str.charAt(from) != '"');
184+
}
175185
}
176-
else if (brackets == 0)
186+
else
177187
{
178188
if (isOneOf(ch, openings))
179189
ops++;

0 commit comments

Comments
 (0)