docs: public static String normalizeUnixStylePath(String path) {
          // OK so this could be a couple of regexps, but this method needs to be FAST.
          // That is best done by walking backwards over a copy of the string, resolving
          // /.. sequences after they are encountered by skipping the next non-.. element.
  
          ///////////////////////////////////////////////////////////
          // NO PARSING - null or empty or single character string //
          ///////////////////////////////////////////////////////////
  
          final int pathLen;
          // cannot require any modification unless there are at least two characters.
          if (path == null || (pathLen = path.length()) < 2)
              return path;
          // start from the end of the path and walk to the start
          int pathIndex = pathLen - 1;
          // track the current parse state
          ParseState state = ParseState.NEW_ELEM;
  
          ///////////////////////////////////////////////
          // FAST PARSING - the path is in normal form //
          ///////////////////////////////////////////////
  
          FAST_PARSING: {
              // Loop BACKWARDS from the final character to the SECOND character.
              // If we get as far as the second character without needing to
              // do any transformation, then the first character can never make
              // any difference and the string will be returned without transformation.
              // Er... the above statement is not true in cases where there is a leading
              // double slash - i.e. //META-INF/resources/someFile.  We need to check the
              // first character in the path string.
              WALKING_BACKWARDS: for (pathIndex = pathLen - 1; pathIndex >= 0; pathIndex--) {
                  final char c = path.charAt(pathIndex);
                  switch (state) {
                      case NEW_ELEM:
                          switch (c) {
                              case '/':
                                  // need to strip trailing or duplicate slashes
                                  // break out to complex parsing
                                  break FAST_PARSING;
                              case '.':
                                  state = ParseState.ONE_DOT;
                                  continue WALKING_BACKWARDS;
                              default:
                                  state = ParseState.IN_ELEM;
                                  continue WALKING_BACKWARDS;
                          }
                      case IN_ELEM:
                          if (c == '/')
                              state = ParseState.NEW_ELEM;
                          continue WALKING_BACKWARDS;
                      case ONE_DOT:
                          switch (c) {
                              case '/':
                                  state = ParseState.NEW_ELEM;
                                  continue WALKING_BACKWARDS;
                              case '.':
                                  state = ParseState.TWO_DOTS;
                                  continue WALKING_BACKWARDS;
                              default:
                                  state = ParseState.IN_ELEM;
                                  continue WALKING_BACKWARDS;
                          }
                      case TWO_DOTS:
                          switch (c) {
                              case '/':
                                  // we've found a "/.." (and it isn't the whole path)
                                  // rewind the last two characters (i.e. so the next loop starts at the first dot)
                                  pathIndex += 2;
                                  // mark that we are at the start of an element so the two dots get parsed correctly
                                  state = ParseState.NEW_ELEM;
                                  // now we've set up the required state, break out to complex parsing
                                  break FAST_PARSING;
                              default:
                                  // anything other than a slash means the two dots were just part of an element with no special meaning
                                  state = ParseState.IN_ELEM;
                                  continue WALKING_BACKWARDS;
                          }
                  }
              }
              return path;
          }
  
          //////////////////////////////////////////////////
          // COMPLEX PARSING - path is not in normal form //
          //////////////////////////////////////////////////
  
          // start with a complete copy of the path - normal form cannot be longer than this
          char[] buffer = path.toCharArray();
          int offset = pathIndex + 1; // offset always points to start of result-so-far
          int elemsToSkip = 0;
          // Loop BACKWARDS from the current character to the SECOND character.
          // The final character is special and is dealt with at the end.
          WALKING_BACKWARDS: for (; pathIndex > 0; pathIndex--) {
              final char c = buffer[pathIndex];
              OUTER_HERE: switch (state) {
                  case NEW_ELEM:
                      switch (c) {
                          case '/':
                              // strip duplicate slash
                              continue WALKING_BACKWARDS;
                          case '.':
                              // strip first dot of element, copy back later if it wasn't "/.."
                              state = ParseState.ONE_DOT;
                              continue WALKING_BACKWARDS;
                          default:
                              state = ParseState.IN_ELEM;
                              if (elemsToSkip > 0)
                                  continue WALKING_BACKWARDS;
                              break OUTER_HERE;
                      }
                  case IN_ELEM:
                      switch (c) {
                          case '/':
                              state = ParseState.NEW_ELEM;
                              if (elemsToSkip == 0)
                                  break OUTER_HERE;
                              elemsToSkip--;
                              continue WALKING_BACKWARDS;
                          default:
                              if (elemsToSkip == 0)
                                  break OUTER_HERE;
                              continue WALKING_BACKWARDS;
                      }
                  case ONE_DOT:
                      switch (c) {
                          case '.':
                              // strip second dot of element, copy back later if it wasn't "/.."
                              state = ParseState.TWO_DOTS;
                              continue WALKING_BACKWARDS;
                          case '/':
                              state = ParseState.NEW_ELEM;
                              if (elemsToSkip == 0) {
                                  // copy the one dot we didn't copy earlier
                                  buffer[--offset] = '.';
                                  break OUTER_HERE;
                              }
                              elemsToSkip--;
                              continue WALKING_BACKWARDS;
                          default:
                              state = ParseState.IN_ELEM;
                              if (elemsToSkip == 0) {
                                  // copy the one dot we didn't copy earlier
                                  buffer[--offset] = '.';
                                  break OUTER_HERE;
  
                              }
                              continue WALKING_BACKWARDS;
                      }
                  case TWO_DOTS:
                      switch (c) {
                          case '/':
                              state = ParseState.NEW_ELEM;
                              // just read in a "/.." so increase the number of elements to skip
                              elemsToSkip++;
                              // never copy this slash
                              continue WALKING_BACKWARDS;
                          default:
                              state = ParseState.IN_ELEM;
                              if (elemsToSkip == 0) {
                                  // copy the two dots we just skipped
                                  buffer[--offset] = '.';
                                  buffer[--offset] = '.';
                                  break OUTER_HERE;
                              }
                              continue WALKING_BACKWARDS;
                      }
              }
              buffer[--offset] = c;
              continue WALKING_BACKWARDS;
          } // end for loop
  
          ///////////////////////////////////////////////////////////
          // COMPLEX PARSING pt II - deal with the final character //
          ///////////////////////////////////////////////////////////
  
          final char c = buffer[0];
          final boolean pathHasLeadingSlash = c == '/';
          // check whether we just finished skipping an element
          // write in any dots that were previously ignored
          // this path has no further scope to collapse them
          switch (state) {
              case IN_ELEM: // FALL-THROUGH
                  if (elemsToSkip == 0)
                      buffer[--offset] = c;
                  else
                      elemsToSkip--;
                  break;
              case ONE_DOT: // treat as IN_ELEM
                  if (elemsToSkip == 0 || c == '.') {
                      buffer[--offset] = '.';
                      buffer[--offset] = c;
                  } else {
                      elemsToSkip--;
                  }
                  break;
              case NEW_ELEM:
                  if (elemsToSkip == 0) {
                      if ((offset == pathLen) || !!!pathHasLeadingSlash)
                          buffer[--offset] = c;
                  } else if (!!!pathHasLeadingSlash) {// one-char path element being skipped
                      elemsToSkip--;
                  }
                  break;
              case TWO_DOTS:
                  if (elemsToSkip == 0 || pathHasLeadingSlash) {
                      buffer[--offset] = '.';
                      buffer[--offset] = '.';
                      buffer[--offset] = c;
                  } else {
                      elemsToSkip--;
                  }
                  break;
          }
  
          if (elemsToSkip == 0) {
              boolean resultHasLeadingSlash = offset < pathLen && buffer[offset] == '/';
              // ensure leading slash matches
              if (pathHasLeadingSlash ^ resultHasLeadingSlash)
                  if (resultHasLeadingSlash)
                      offset++; //strip a leading slash
                  else
                      buffer[--offset] = '/'; // add a leading slash
          } else {
              // ensure we have a leading slash or empty string before prepending ".."
              if (offset < pathLen && buffer[offset] != '/')
                  buffer[--offset] = '/';
              // add in all but one unresolved "/.."
              while (--elemsToSkip > 0) {
                  buffer[--offset] = '.';
                  buffer[--offset] = '.';
                  buffer[--offset] = '/';
              }
              // now write in the last .. or /..
              buffer[--offset] = '.';
              buffer[--offset] = '.';
              if (pathHasLeadingSlash)
                  buffer[--offset] = '/';
          }
          return new String(buffer, offset, pathLen - offset);
      }