code: private static int indexOfDotOrSquare(String propertyPattern) {
          int lenght = propertyPattern.length();
          int result = 0;// nothing found
  
          boolean dotFound = false;
          boolean insideSquares = false;
  
          int i = 0;
          while (!dotFound && i < lenght) {
              char current = propertyPattern.charAt(i);
  
              if (!insideSquares) {
                  if (current == '.') {
                      dotFound = true;
                      result = i;// found: set as positive and stop the loop
                  } else if (current == '[') {
                      insideSquares = true;
                      result = -i;// found: set as negative, but still continuing...
                  }
              } else {
                  if (current == ']') {
                      insideSquares = false;
                  }
              }
  
              i++;
          }
  
          if (insideSquares) {
              throw new IllegalArgumentException("Cannot found the closing ']' suffix in '" + propertyPattern + "' pattern.");
          }
  
          return result;
      }
docs: Optimized version of indexOf that searches both '.' and '[' positions
  using just a sigle loop, while taking in consideration (and ignoring)
  possible dots inside the square notation (like "map[foo.bar].zoo").
  
  <p> The searching process will stop immediately at the first '.' found,
  hence the result order matters: '.' has precedence over '[' notation.
  
  <p> To avoid the need of a new object for containing both results (gc),
  the alghoritm will return as a positive int value the '.' first position,
  and as a negative int value the negated '[' first position.
  
  <p> A result == 0 means "not found", as a propertyPattern with the first
  char equal to '.' or '[', in [0] position, is an illegal pattern anyway.
  
  @param propertyPattern the pattern to parse, cannot be {@code null}
  @return the first '.' position (if any), or
  the negated first '[' position (if any and no '.' found before), or
  0 if neither '.' nor ']' was found, or no valid pattern present
  @throws IllegalArgumentException if the whole string was parsed but '[x]'
  notation is still "open" without an enclosing ']'