@@ -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 {
0 commit comments