Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright 2000-2013  The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  // March 5, 2015 - rwhogg - removed unnecessary return statement
  
  package nu.validator.datatype;
  
  
  
  public class SvgPathData extends AbstractDatatype {

    
Package-private constructor
  
      protected SvgPathData() {
          super();
      }
  
      private static StringReader reader;
  
      private static StringBuilder context;
  
      private static final int MAX_CONTEXT_LENGTH = 20;
  
      private void appendToContext(int i) {
          if (i != -1) {
              if (.length() == ) {
                  .deleteCharAt(0);
              }
              .append((chari);
          }
      }

    
The current character.
  
      private int current;
  
      @Override public void checkValid(CharSequence literal)
              throws DatatypeException {
  
           = new StringReader(literal.toString());
           = new StringBuilder();
  
          try {
               = .read();
              appendToContext();
          } catch (IOException e) {
              throw new RuntimeException(e);
          }
  
          loop: for (;;) {
              try {
                  switch () {
                      case 0xD:
                      case 0xA:
                      case 0x20:
                      case 0x9:
                           = .read();
                          appendToContext();
                          break;
                      case 'z':
                      case 'Z':
                           = .read();
                          appendToContext();
                          break;
                      case 'm':
                          checkm();
                          break;
                      case 'M':
                          checkM();
                          break;
                      case 'l':
                          checkl();
                          break;
                      case 'L':
                          checkL();
                          break;
                      case 'h':
                          checkh();
                          break;
                      case 'H':
                         checkH();
                         break;
                     case 'v':
                         checkv();
                         break;
                     case 'V':
                         checkV();
                         break;
                     case 'c':
                         checkc();
                         break;
                     case 'C':
                         checkC();
                         break;
                     case 'q':
                         checkq();
                         break;
                     case 'Q':
                         checkQ();
                         break;
                     case 's':
                         checks();
                         break;
                     case 'S':
                         checkS();
                         break;
                     case 't':
                         checkt();
                         break;
                     case 'T':
                         checkT();
                         break;
                     case 'a':
                         checka();
                         break;
                     case 'A':
                         checkA();
                         break;
                     case -1:
                         break loop;
                     default:
                         throw newDatatypeException("Expected command but "
                                 + "found \u201c" + (char
                                 + "\u201d (context: \u201c"
                                 + .toString() + "\u201d).");
                 }
             } catch (IOException e) {
                 try {
                     skipSubPath();
                 } catch (IOException ioe) {
                     throw new RuntimeException(ioe);
                 }
                 throw new RuntimeException(e);
             }
         }
 
         try {
             skipSpaces();
             if ( != -1) {
                 throw newDatatypeException("Found unexpected character "
                         + "\u201c" + (char + "\u201d.");
             }
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }

    
Checks an 'm' command.
 
     private void checkm() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
 
         checkArg('m'"x coordinate");
         skipCommaSpaces();
         checkArg('m'"y coordinate");
 
         boolean expectNumber = skipCommaSpaces2();
         _checkl('m'expectNumber);
     }

    
Checks an 'M' command.
 
     private void checkM() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
 
         checkArg('M'"x coordinate");
         skipCommaSpaces();
         checkArg('M'"y coordinate");
 
         boolean expectNumber = skipCommaSpaces2();
         _checkL('M'expectNumber);
     }

    
Checks an 'l' command.
 
     private void checkl() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         _checkl('l'true);
     }
 
     private void _checkl(char commandboolean expectNumber)
             throws IOExceptionDatatypeException {
         for (;;) {
             switch () {
                 default:
                     if (expectNumber) {
                         reportUnexpected("coordinate pair for " + "\u201c"
                                 + command + "\u201d command");
                         skipSubPath();
                     }
                     return;
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
             checkArg(command"x coordinate");
             skipCommaSpaces();
             checkArg(command"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks an 'L' command.
 
     private void checkL() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         _checkL('L'true);
     }
 
     private void _checkL(char commandboolean expectNumber)
             throws IOExceptionDatatypeException {
         for (;;) {
             switch () {
                 default:
                     if (expectNumber) {
                         reportUnexpected("coordinate pair for " + "\u201c"
                                 + command + "\u201d command");
                         skipSubPath();
                     }
                     return;
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
             checkArg(command"x coordinate");
             skipCommaSpaces();
             checkArg(command"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks an 'h' command.
 
     private void checkh() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('h');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
             checkArg('h'"x coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks an 'H' command.
 
     private void checkH() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('H');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
             checkArg('H'"x coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 'v' command.
 
     private void checkv() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('v');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
             checkArg('v'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 'V' command.
 
     private void checkV() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('V');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
             checkArg('V'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 'c' command.
 
     private void checkc() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('c');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('c'"x1 coordinate");
             skipCommaSpaces();
             checkArg('c'"y1 coordinate");
             skipCommaSpaces();
             checkArg('c'"x2 coordinate");
             skipCommaSpaces();
             checkArg('c'"y2 coordinate");
             skipCommaSpaces();
             checkArg('c'"x coordinate");
             skipCommaSpaces();
             checkArg('c'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 'C' command.
 
     private void checkC() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('C');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('C'"x1 coordinate");
             skipCommaSpaces();
             checkArg('C'"y1 coordinate");
             skipCommaSpaces();
             checkArg('C'"x2 coordinate");
             skipCommaSpaces();
             checkArg('C'"y2 coordinate");
             skipCommaSpaces();
             checkArg('C'"x coordinate");
             skipCommaSpaces();
             checkArg('C'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 'q' command.
 
     private void checkq() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('q');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('q'"x1 coordinate");
             skipCommaSpaces();
             checkArg('q'"y1 coordinate");
             skipCommaSpaces();
             checkArg('q'"x coordinate");
             skipCommaSpaces();
             checkArg('q'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 'Q' command.
 
     private void checkQ() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('Q');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('Q'"x1 coordinate");
             skipCommaSpaces();
             checkArg('Q'"y1 coordinate");
             skipCommaSpaces();
             checkArg('Q'"x coordinate");
             skipCommaSpaces();
             checkArg('Q'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks an 's' command.
 
     private void checks() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('s');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('s'"x2 coordinate");
             skipCommaSpaces();
             checkArg('s'"y2 coordinate");
             skipCommaSpaces();
             checkArg('s'"x coordinate");
             skipCommaSpaces();
             checkArg('s'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks an 'S' command.
 
     private void checkS() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('S');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('S'"x2 coordinate");
             skipCommaSpaces();
             checkArg('S'"y2 coordinate");
             skipCommaSpaces();
             checkArg('S'"x coordinate");
             skipCommaSpaces();
             checkArg('S'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 't' command.
 
     private void checkt() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('t');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('t'"x coordinate");
             skipCommaSpaces();
             checkArg('t'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a 'T' command.
 
     private void checkT() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('T');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('T'"x coordinate");
             skipCommaSpaces();
             checkArg('T'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks an 'a' command.
 
     private void checka() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('a');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('a'"rx radius");
             skipCommaSpaces();
             checkArg('a'"ry radius");
             skipCommaSpaces();
             checkArg('a'"x-axis-rotation");
             skipCommaSpaces();
 
             switch () {
                 default:
                     reportUnexpected("\u201c0\u201d or \u201c1\u201d "
                             + "for large-arc-flag for \u201ca\u201d command",
                             );
                     skipSubPath();
                     return;
                 case '0':
                 case '1':
                     break;
             }
 
              = .read();
             appendToContext();
             skipCommaSpaces();
 
             switch () {
                 default:
                     reportUnexpected("\u201c0\u201d or \u201c1\u201d "
                             + "for sweep-flag for \u201ca\u201d command",
                             );
                     skipSubPath();
                     return;
                 case '0':
                 case '1':
                     break;
             }
 
              = .read();
             appendToContext();
             skipCommaSpaces();
 
             checkArg('a'"x coordinate");
             skipCommaSpaces();
             checkArg('a'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks an 'A' command.
 
     private void checkA() throws DatatypeExceptionIOException {
         if (.length() == 0) {
             appendToContext();
         }
          = .read();
         appendToContext();
         skipSpaces();
         boolean expectNumber = true;
 
         for (;;) {
             switch () {
                 default:
                     if (expectNumber)
                         reportNonNumber('A');
                     return;
 
                 case '+':
                 case '-':
                 case '.':
                 case '0':
                 case '1':
                 case '2':
                 case '3':
                 case '4':
                 case '5':
                 case '6':
                 case '7':
                 case '8':
                 case '9':
                     break;
             }
 
             checkArg('A'"rx radius");
             skipCommaSpaces();
             checkArg('A'"ry radius");
             skipCommaSpaces();
             checkArg('A'"x-axis-rotation");
             skipCommaSpaces();
 
             switch () {
                 default:
                     reportUnexpected("\u201c0\u201d or \u201c1\u201d "
                             + "for large-arc-flag for \u201cA\u201d command",
                             );
                     skipSubPath();
                     return;
                 case '0':
                 case '1':
                     break;
             }
 
              = .read();
             appendToContext();
             skipCommaSpaces();
 
             switch () {
                 default:
                     reportUnexpected("\u201c0\u201d or \u201c1\u201d "
                             + "for sweep-flag for \u201cA\u201d command",
                             );
                     skipSubPath();
                     return;
                 case '0':
                 case '1':
                     break;
             }
 
              = .read();
             appendToContext();
             skipCommaSpaces();
 
             checkArg('A'"x coordinate");
             skipCommaSpaces();
             checkArg('A'"y coordinate");
 
             expectNumber = skipCommaSpaces2();
         }
     }

    
Checks a command argument.
    private void checkArg(char commandString argthrows DatatypeException,
            IOException {
        int mant = 0;
        int mantDig = 0;
        boolean mantPos = true;
        boolean mantRead = false;
        int exp = 0;
        int expDig = 0;
        int expAdj = 0;
        boolean expPos = true;
        switch () {
            case '-':
                mantPos = false;
            case '+':
                 = .read();
                appendToContext();
        }
        m1: switch () {
            default:
                reportUnexpected(arg + " for \u201c" + command
                        + "\u201d command");
                skipSubPath();
                return;
            case '.':
                break;
            case '0':
                mantRead = true;
                l: for (;;) {
                     = .read();
                    appendToContext();
                    switch () {
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
                            break l;
                        case '.':
                        case 'e':
                        case 'E':
                            break m1;
                        default:
                            return;
                        case '0':
                    }
                }
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                mantRead = true;
                l: for (;;) {
                    if (mantDig < 9) {
                        mantDig++;
                        mant = mant * 10 + ( - '0');
                    } else {
                        expAdj++;
                    }
                     = .read();
                    appendToContext();
                    switch () {
                        default:
                            break l;
                        case '0':
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
                    }
                }
        }
        if ( == '.') {
             = .read();
            appendToContext();
            m2: switch () {
                default:
                case 'e':
                case 'E':
                    if (!mantRead) {
                        reportNonNumber(command);
                        return;
                    }
                    break;
                case '0':
                    if (mantDig == 0) {
                        l: for (;;) {
                             = .read();
                            appendToContext();
                            expAdj--;
                            switch () {
                                case '1':
                                case '2':
                                case '3':
                                case '4':
                                case '5':
                                case '6':
                                case '7':
                                case '8':
                                case '9':
                                    break l;
                                default:
                                    if (!mantRead) {
                                        return;
                                    }
                                    break m2;
                                case '0':
                            }
                        }
                    }
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    l: for (;;) {
                        if (mantDig < 9) {
                            mantDig++;
                            mant = mant * 10 + ( - '0');
                            expAdj--;
                        }
                         = .read();
                        appendToContext();
                        switch () {
                            default:
                                break l;
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                        }
                    }
            }
        }
        switch () {
            case 'e':
            case 'E':
                 = .read();
                appendToContext();
                switch () {
                    default:
                        reportNonNumber(command);
                        return;
                    case '-':
                        expPos = false;
                    case '+':
                         = .read();
                        appendToContext();
                        switch () {
                            default:
                                reportNonNumber(command);
                                return;
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                        }
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                }
                en: switch () {
                    case '0':
                        l: for (;;) {
                             = .read();
                            appendToContext();
                            switch () {
                                case '1':
                                case '2':
                                case '3':
                                case '4':
                                case '5':
                                case '6':
                                case '7':
                                case '8':
                                case '9':
                                    break l;
                                default:
                                    break en;
                                case '0':
                            }
                        }
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        l: for (;;) {
                            if (expDig < 3) {