@@ -466,7 +466,8 @@ public static StringBuilder multilpy(CharSequence str, int times)
466
466
* @param s | String to split and check some syntax.
467
467
* @param splitter | Chars where string will be split!
468
468
*
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 '}
470
471
*
471
472
* @since 1.0.0
472
473
*/
@@ -483,7 +484,8 @@ public static String[] splitValues(String s, char... splitter)
483
484
* <b>If 2</b>, splitting will occur after any number of splitters, n number of splitters in row will be treated as 1!
484
485
* @param splitter | Chars where string will be split!
485
486
*
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 '}'
487
489
*
488
490
* @since 1.3.0
489
491
*/
@@ -501,7 +503,8 @@ public static String[] splitValues(String s, int limit, int splittingStrategy, c
501
503
* @param splitBreaks | When some of these characters is encountered, splitting is terminated for the rest of the string!
502
504
* @param splitter | Chars where string will be split!
503
505
*
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 '}'
505
508
*
506
509
* @since 1.3.5
507
510
*/
@@ -517,10 +520,11 @@ public static String[] splitValues(String s, int limit, int splittingStrategy, c
517
520
* @param splittingStrategy | <b>If 0</b>, splitting will occur after each splitter!
518
521
* <b>If 1</b>, string will be splitted after only one splitter, more than one splitters in row will be ignored!
519
522
* <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!
521
524
* @param splitter | Chars where string will be split!
522
525
*
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 '}'
524
528
*
525
529
* @since 1.3.8
526
530
*/
@@ -534,51 +538,47 @@ public static String[] splitValues(String s, int i, int limit, int splittingStra
534
538
535
539
List <String > result = new ArrayList <>();
536
540
537
- int brackets = 0 , lastIndex = 0 , len = s .length ();
541
+ int lastIndex = 0 , len = s .length ();
538
542
for (int count = 1 , oldCh = 0 ; i < len && (limit <= 0 || count < limit ); i ++)
539
543
{
540
- char ch = s .charAt (i );
544
+ int ch = s .charAt (i );
541
545
if (ch == '"' )
542
546
{
543
547
do if (++i >= len )
544
548
throw new IllegalArgumentException ("Unclosed or missing quotes in: " + s );
545
549
while (s .charAt (i ) != '"' );
546
550
}
547
- else
551
+ else if (( ch | ' ' ) == '{' )
548
552
{
549
- if ( isOneOf ( ch , splitBreaks ) )
553
+ for ( int brackets = 1 ; brackets != 0 ; )
550
554
{
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 ) != '"' );
566
563
}
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 ())
570
572
{
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 ++ ;
575
577
}
576
578
}
579
+
577
580
oldCh = ch ;
578
581
}
579
-
580
- if (brackets > 0 )
581
- throw new IllegalArgumentException ("Unclosed brackets in: " + s );
582
582
583
583
result .add (s .substring (lastIndex , len ).trim ());
584
584
return result .toArray (new String [0 ]);
@@ -611,26 +611,31 @@ public static int indexOfNotInObj(CharSequence s, char... oneOf)
611
611
*/
612
612
public static int indexOfNotInObj (CharSequence s , int from , int to , int defaultReturn , boolean firstIndex , char ... oneOf )
613
613
{
614
- for (int brackets = 0 ; from < to ; from ++)
614
+ for (; from < to ; from ++)
615
615
{
616
- char ch = s .charAt (from );
616
+ int ch = s .charAt (from );
617
617
if (ch == '"' )
618
618
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 ))
620
634
{
621
635
if (firstIndex )
622
636
return from ;
623
637
defaultReturn = from ;
624
638
}
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
- }
634
639
}
635
640
return defaultReturn ;
636
641
}
@@ -665,21 +670,26 @@ public static int indexOfNotInObj(CharSequence s, int from, int to, int defaultR
665
670
if (sequencesToFind .length < 1 )
666
671
return defaultReturn ;
667
672
668
- for (int brackets = 0 ; from < to ; from ++)
673
+ for (; from < to ; from ++)
669
674
{
670
- char ch = s .charAt (from );
675
+ int ch = s .charAt (from );
671
676
if (ch == '"' )
672
677
while (++from < to && s .charAt (from ) != '"' );
673
678
else if ((ch | ' ' ) == '{' )
674
- brackets ++;
675
- else if ((ch | ' ' ) == '}' )
676
679
{
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
+ }
681
691
}
682
- else if ( brackets == 0 )
692
+ else
683
693
{
684
694
findMatch : for (int cur = 0 , seqsLen = sequencesToFind .length ; cur < seqsLen ; cur ++)
685
695
{
0 commit comments