Checks a set of characters, throws IOException if invalid
437048
public static void checkCharacters(CharSequence str, int off, int end) throws IOException {
		while(off < end) checkCharacter(str.charAt(off++));
	}
471211
void readRegExp(int startToken)
        throws IOException
    {
        int start = tokenBeg;
        stringBufferTop = 0;
        if (startToken == Token.ASSIGN_DIV) {
            // Miss-scanned /=
            addToString('=');
        } else {
            if (startToken != Token.DIV) Kit.codeBug();
        }

        boolean inCharSet = false; // true if inside a '['..']' pair
        int c;
        while ((c = getChar()) != '/' || inCharSet) {
            if (c == '\n' || c == EOF_CHAR) {
                ungetChar(c);
                tokenEnd = cursor - 1;
                this.string = new String(stringBuffer, 0, stringBufferTop);
                parser.reportError("msg.unterminated.re.lit");
                return;
            }
            if (c == '\\') {
                addToString(c);
                c = getChar();
            } else if (c == '[') {
                inCharSet = true;
            } else if (c == ']') {
                inCharSet = false;
            }
            addToString(c);
        }
        int reEnd = stringBufferTop;

        while (true) {
            if (matchChar('g'))
                addToString('g');
            else if (matchChar('i'))
                addToString('i');
            else if (matchChar('m'))
                addToString('m');
            else if (matchChar('y'))  // FireFox 3
                addToString('y');
            else
                break;
        }
        tokenEnd = start + stringBufferTop + 2;  // include slashes

        if (isAlpha(peekChar())) {
            parser.reportError("msg.invalid.re.flag");
        }

        this.string = new String(stringBuffer, 0, reEnd);
        this.regExpFlags = new String(stringBuffer, reEnd,
                                      stringBufferTop - reEnd);
    }
96167
private void checkException(DataInputStream inputStream) throws IOException {
        short retCode = inputStream.readShort();
        if(retCode != 0) {
            String error = inputStream.readUTF();
            throw mapper.getError(retCode, error);
        }
    }
9863
private static void checkByte(int ch, int pos, int len) throws IOException {
    if ((ch & 0xc0) != 0x80) {
      throw new IOException(
          GT.tr("Illegal UTF-8 sequence: byte {0} of {1} byte sequence is not 10xxxxxx: {2}",
              pos, len, ch));
    }
  }
394890
int get() throws IOException {
		int c = in.read();

		if (c >= ' ' || c == '\n' || c == EOF) {
			return c;
		}

		if (c == '\r') {
			return '\n';
		}
		
		return ' ';
	}
685331
private boolean scanHeaders()
    throws IOException
  {
    int ch = read();
    long length = 0;

    _headers.clear();
    while (ch > 0 && ch != '\n' && ch != '\r') {
      _line.clear();

      _line.append((char) ch);
      for (ch = read();
           ch >= 0 && ch != '\n' && ch != '\r';
           ch = read()) {
        _line.append((char) ch);

        if (_maxLength < length++)
          throw new IOException(L.l("header length {0} exceeded.", _maxLength));
      }

      if (ch == '\r') {
        if ((ch = read()) == '\n')
          ch = read();
      }
      else if (ch == '\n')
        ch = read();

      int i = 0;
      for (; i < _line.length() && _line.charAt(i) != ':'; i++) {
      }

      String key = null;
      String value = null;
      if (i < _line.length()) {
        key = _line.substring(0, i).trim().toLowerCase(Locale.ENGLISH);
        value = _line.substring(i + 1).trim();

        List<String> values = _headers.get(key);

        if (values == null) {
          values = new ArrayList<>();
        }

        values.add(value);

        _headers.put(key, values);
      }
    }

    if (ch == '\r') {
      if ((ch = read()) != '\n') {
        _peek[0] = (byte) ch;
        _peekOffset = 0;
        _peekLength = 1;
      }
    }

    return true;
  }
589520
private void checkHexDigit(int c) throws IOException {
        if (c >= '0' && c <= '9') {
            return;
        }
        if (c >= 'a' && c <= 'f') {
            return;
        }
        if (c >= 'A' && c <= 'F') {
            return;
        }
        // Causes the invalid escape to be skipped
        hasNextChar = true;
        nextChar = c;
        throw new IOException("Did not find four digit hex character code."
                + " line: " + lexer.getLine() + " col:" + lexer.getColumn());
    }
583736
@Override
	public void setInput(InputStream is, String charset) {
		position = 0;
		limit = 0;
		boolean detectCharset = (charset == null);

		if (is == null) {
			throw new IllegalArgumentException();
		}

		try {
			if (detectCharset) {
				// read the four bytes looking for an indication of the encoding
				// in use
				int firstFourBytes = 0;
				while (limit < 4) {
					int i = is.read();
					if (i == -1) {
						break;
					}
					firstFourBytes = (firstFourBytes << 8) | i;
					buffer[limit++] = (char) i;
				}

				if (limit == 4) {
					switch (firstFourBytes) {
					case 0x00000FEFF: // UTF-32BE BOM
						charset = "UTF-32BE";
						limit = 0;
						break;

					case 0x0FFFE0000: // UTF-32LE BOM
						charset = "UTF-32LE";
						limit = 0;
						break;

					case 0x0000003c: // '<' in UTF-32BE
						charset = "UTF-32BE";
						buffer[0] = '<';
						limit = 1;
						break;

					case 0x03c000000: // '<' in UTF-32LE
						charset = "UTF-32LE";
						buffer[0] = '<';
						limit = 1;
						break;

					case 0x0003c003f: // "<?" in UTF-16BE
						charset = "UTF-16BE";
						buffer[0] = '<';
						buffer[1] = '?';
						limit = 2;
						break;

					case 0x03c003f00: // "<?" in UTF-16LE
						charset = "UTF-16LE";
						buffer[0] = '<';
						buffer[1] = '?';
						limit = 2;
						break;

					case 0x03c3f786d: // "<?xm" in ASCII etc.
						while (true) {
							int i = is.read();
							if (i == -1) {
								break;
							}
							buffer[limit++] = (char) i;
							if (i == '>') {
								String s = new String(buffer, 0, limit);
								int i0 = s.indexOf("encoding");
								if (i0 != -1) {
									while (s.charAt(i0) != '"' && s.charAt(i0) != '\'') {
										i0++;
									}
									char deli = s.charAt(i0++);
									int i1 = s.indexOf(deli, i0);
									charset = s.substring(i0, i1);
								}
								break;
							}
						}
						break;

					default:
						// handle a byte order mark followed by something other
						// than <?
						if ((firstFourBytes & 0x0ffff0000) == 0x0feff0000) {
							charset = "UTF-16BE";
							buffer[0] = (char) ((buffer[2] << 8) | buffer[3]);
							limit = 1;
						} else if ((firstFourBytes & 0x0ffff0000) == 0x0fffe0000) {
							charset = "UTF-16LE";
							buffer[0] = (char) ((buffer[3] << 8) | buffer[2]);
							limit = 1;
						} else if ((firstFourBytes & 0x0ffffff00) == 0x0efbbbf00) {
							charset = "UTF-8";
							buffer[0] = buffer[3];
							limit = 1;
						}
					}
				}
			}

			if (charset == null) {
				charset = "UTF-8";
			}

			int savedLimit = limit;
			setInput(new InputStreamReader(is, charset));
			encoding = charset;
			limit = savedLimit;

			/*
			 * Skip the optional BOM if we didn't above. This decrements limit
			 * rather than incrementing position so that <?xml version='1.0'?>
			 * is still at character 0.
			 */
			if (!detectCharset && peekCharacter() == 0xfeff) {
				limit--;
				System.arraycopy(buffer, 1, buffer, 0, limit);
			}
		} catch (Exception e) {
			throw new KriptonRuntimeException("Invalid stream or encoding: " + e, true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), e);
		}
	}
262161
private boolean validCharacters(String value) {
        if (INVALID_CHARACTERS.contains(value)) {
            LOG.error("Flash key or value can not contain the following characters: spaces, |, & or :");
            return false;
        }

        return true;
    }
466725
private int scan(String string, int i, CharBuffer cb, boolean dash)
    throws Exception
  {
    char ch;

    cb.length(0);

    int strlen = string.length();
    for (; i < strlen; i++) {
      if (! Character.isWhitespace(ch = string.charAt(i)) &&
          (ch != ':' && (! dash || ch != '-')))
        break;
    }

    for (; i < strlen; i++) {
      if (! Character.isWhitespace(ch = string.charAt(i)) &&
          (ch != ':' && (! dash || ch != '-')))
        cb.append((char) ch);
      else
        break;
    }

    if (cb.length() == 0)
      throw new Exception();

    return i;
  }
1101806
private String check() throws InvalidExpressionException {

        expression = expression.replaceAll("\\s","");
        expression = expression.toLowerCase();
        String var = "";

        if(expression.length() == 0) {
            throw new InvalidExpressionException("Empty Expression");
        }

        if(!expression.matches("[a-zA-Z0-9+*/^()-]+")) { // contains only operators, numbers, or letters
            throw new InvalidExpressionException("Syntax Error");
        }

        if(expression.matches("[+*/^()-]+")) { // doesn't contain any operands
            throw new InvalidExpressionException("Syntax Error");
        }

        String firstChar = expression.substring(0, 1);
        String lastChar = expression.substring(expression.length() - 1, expression.length());

        if(!firstChar.equals("-") && isOperator(firstChar) || firstChar.equals(")") || isOperator(lastChar) || lastChar.equals("(")) {
            throw new InvalidExpressionException("Syntax Error");
        }


        for(int i = 0; i < expression.length(); i++) {

            String temp = "";

            while(i < expression.length() && expression.substring(i, i + 1).matches("[a-zA-Z]")) {
                temp += expression.substring(i, i + 1);
                i++;
            }

            if(temp.length() == 1) {
                //i--; // ?? i must be decremented from the above while loop in this if block so the program can check the last character in the string
                if(var.length() == 0)
                    var = temp;
                if(!temp.equals(var)) {
                    throw new InvalidExpressionException("For now, expression must contain a single variable");
                }
                else if(i < expression.length() && expression.substring(i, i + 1).matches("[0-9]+")) {
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if(isFunction(temp)) {

                if(i < expression.length()) {
                    if(!expression.substring(i, i + 1).equals("(")) {
                        //System.out.println("Syntax Error: " + temp + " needs a parenthesis after it");// no parenthesis after function (EX: sin5)
                        throw new InvalidExpressionException("Syntax Error");
                    }
                }
                else {
                    //System.out.println("Syntax Error: " + temp + " needs an input"); // nothing after function (EX: 5 + sin)
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if(temp.length() != 0){
                //System.out.println(temp + ": function not found");
                throw new InvalidExpressionException(temp + ": function not found");
            }

            //i--; // ?? i must be decremented since it was left incremented in the above while loop
        }


        int cntOpenParen = 0;
        int cntCloseParen = 0;

        for(int i = 0; i < expression.length() - 1; i++) {

            String tmp1 = expression.substring(i, i + 1);
            String tmp2 = expression.substring(i + 1, i + 2);

            if(tmp1.equals("-")) {
                if(isOperator(tmp2) || tmp2.equals(")")) {
                    //System.out.println("Syntax Error: " + tmp1 + tmp2);
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if(tmp2.equals("-")) { // Also prevents next else if from rejecting an operator followed by a unary minus
                if(tmp1.equals("(")) {
                    //System.out.println("Syntax Error: " + tmp1 + tmp2);
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if((isOperator(tmp1) || tmp1.equals("(")) && (isOperator(tmp2) || tmp2.equals(")"))) {
                //System.out.println("Syntax Error: " + tmp1 + tmp2); // two operands in a row (examples: ++, (+, ())
                throw new InvalidExpressionException("Syntax Error");
            }
            else if(expression.substring(i, i + 1).equals("("))
                cntOpenParen++;
            else if(expression.substring(i, i + 1).equals(")"))
                cntCloseParen++;
        }

        if(cntOpenParen < cntCloseParen) { // found a ")" when the end of the expression was expected
            //System.out.println("Syntax Error: found ')' but expected end of expression");
            throw new InvalidExpressionException("Syntax Error");
        }

        return var;
    }
41571
protected void readUntil(char echar) throws IOException
    {
        int ch, i = 0;
        IStringBuffer sb = new IStringBuffer();
        while ( (ch = readNext()) != -1 ) {
            if ( ++i >= MAX_QUOTE_LENGTH ) {
                /*
                 * push back the readed chars
                 * and reset the global idx value. 
                */
                for ( int j = sb.length() - 1; j >= 0; j-- ) {
                    reader.unread(sb.charAt(j));
                }
                idx -= sb.length();
                break;
            }
            
            sb.append((char)ch);
            if ( ch == echar ) {
                gisb.append(sb.toString());
                break;
            }
        }
        
        sb = null;
    }
908803
def _check(self, terms):
        """"""
        for t in terms:
            try:
                _ = urllib.parse.quote(six.text_type(t).encode('utf8'))
            except:
                self.logger.error('Unknown character in [{0}]!'.format(t))
                self.logger.error('.... remove character and try again.')
                raise EncodingError
454652
private static boolean isValidChar(char c) {
        if ( c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' ) {
            return true;
        }
        return c != ' ' && c != '\u00A0' && !Character.isWhitespace(c) && !Character.isWhitespace(c);
    }
1281585
private void processText() {

        int length = content.length();
        int i, j, count, current_set;

        if (length > 138) {
            throw new OkapiException("Input data too long");
        }

        for (i = 0; i < 144; i++) {
            set[i] = -1;
            character[i] = 0;
        }

        for (i = 0; i < length; i++) {
            /* Look up characters in table from Appendix A - this gives
             value and code set for most characters */
            set[i] = MAXICODE_SET[inputData[i]];
            character[i] = MAXICODE_SYMBOL_CHAR[inputData[i]];
        }

        // If a character can be represented in more than one code set, pick which version to use.
        if (set[0] == 0) {
            if (character[0] == 13) {
                character[0] = 0;
            }
            set[0] = 1;
        }

        for (i = 1; i < length; i++) {
            if (set[i] == 0) {
                /* Special character that can be represented in more than one code set. */
                if (character[i] == 13) {
                    /* Carriage Return */
                    set[i] = bestSurroundingSet(i, length, 1, 5);
                    if (set[i] == 5) {
                        character[i] = 13;
                    } else {
                        character[i] = 0;
                    }
                } else if (character[i] == 28) {
                    /* FS */
                    set[i] = bestSurroundingSet(i, length, 1, 2, 3, 4, 5);
                    if (set[i] == 5) {
                        character[i] = 32;
                    }
                } else if (character[i] == 29) {
                    /* GS */
                    set[i] = bestSurroundingSet(i, length, 1, 2, 3, 4, 5);
                    if (set[i] == 5) {
                        character[i] = 33;
                    }
                } else if (character[i] == 30) {
                    /* RS */
                    set[i] = bestSurroundingSet(i, length, 1, 2, 3, 4, 5);
                    if (set[i] == 5) {
                        character[i] = 34;
                    }
                } else if (character[i] == 32) {
                    /* Space */
                    set[i] = bestSurroundingSet(i, length, 1, 2, 3, 4, 5);
                    if (set[i] == 1) {
                        character[i] = 32;
                    } else if (set[i] == 2) {
                        character[i] = 47;
                    } else {
                        character[i] = 59;
                    }
                } else if (character[i] == 44) {
                    /* Comma */
                    set[i] = bestSurroundingSet(i, length, 1, 2);
                    if (set[i] == 2) {
                        character[i] = 48;
                    }
                } else if (character[i] == 46) {
                    /* Full Stop */
                    set[i] = bestSurroundingSet(i, length, 1, 2);
                    if (set[i] == 2) {
                        character[i] = 49;
                    }
                } else if (character[i] == 47) {
                    /* Slash */
                    set[i] = bestSurroundingSet(i, length, 1, 2);
                    if (set[i] == 2) {
                        character[i] = 50;
                    }
                } else if (character[i] == 58) {
                    /* Colon */
                    set[i] = bestSurroundingSet(i, length, 1, 2);
                    if (set[i] == 2) {
                        character[i] = 51;
                    }
                }
            }
        }

        for (i = length; i < set.length; i++) {
            /* Add the padding */
            if (set[length - 1] == 2) {
                set[i] = 2;
            } else {
                set[i] = 1;
            }
            character[i] = 33;
        }

        /* Find candidates for number compression (not allowed in primary message in modes 2 and 3). */
        if (mode == 2 || mode == 3) {
            j = 9;
        } else {
            j = 0;
        }
        count = 0;
        for (i = j; i < 143; i++) {
            if (set[i] == 1 && character[i] >= 48 && character[i] <= 57) {
                /* Character is a number */
                count++;
            } else {
                count = 0;
            }
            if (count == 9) {
                /* Nine digits in a row can be compressed */
                set[i] = 6;
                set[i - 1] = 6;
                set[i - 2] = 6;
                set[i - 3] = 6;
                set[i - 4] = 6;
                set[i - 5] = 6;
                set[i - 6] = 6;
                set[i - 7] = 6;
                set[i - 8] = 6;
                count = 0;
            }
        }

        /* Add shift and latch characters */
        current_set = 1;
        i = 0;
        do {
            if ((set[i] != current_set) && (set[i] != 6)) {
                switch (set[i]) {
                    case 1:
                        if (i + 1 < set.length && set[i + 1] == 1) {
                            if (i + 2 < set.length && set[i + 2] == 1) {
                                if (i + 3 < set.length && set[i + 3] == 1) {
                                    /* Latch A */
                                    insert(i, 63);
                                    current_set = 1;
                                    length++;
                                    i += 3;
                                } else {
                                    /* 3 Shift A */
                                    insert(i, 57);
                                    length++;
                                    i += 2;
                                }
                            } else {
                                /* 2 Shift A */
                                insert(i, 56);
                                length++;
                                i++;
                            }
                        } else {
                            /* Shift A */
                            insert(i, 59);
                            length++;
                        }
                        break;
                    case 2:
                        if (i + 1 < set.length && set[i + 1] == 2) {
                            /* Latch B */
                            insert(i, 63);
                            current_set = 2;
                            length++;
                            i++;
                        } else {
                            /* Shift B */
                            insert(i, 59);
                            length++;
                        }
                        break;
                    case 3:
                        if (i + 3 < set.length && set[i + 1] == 3 && set[i + 2] == 3 && set[i + 3] == 3) {
                            /* Lock In C */
                            insert(i, 60);
                            insert(i, 60);
                            current_set = 3;
                            length++;
                            i += 3;
                        } else {
                            /* Shift C */
                            insert(i, 60);
                            length++;
                        }
                        break;
                    case 4:
                        if (i + 3 < set.length && set[i + 1] == 4 && set[i + 2] == 4 && set[i + 3] == 4) {
                            /* Lock In D */
                            insert(i, 61);
                            insert(i, 61);
                            current_set = 4;
                            length++;
                            i += 3;
                        } else {
                            /* Shift D */
                            insert(i, 61);
                            length++;
                        }
                        break;
                    case 5:
                        if (i + 3 < set.length && set[i + 1] == 5 && set[i + 2] == 5 && set[i + 3] == 5) {
                            /* Lock In E */
                            insert(i, 62);
                            insert(i, 62);
                            current_set = 5;
                            length++;
                            i += 3;
                        } else {
                            /* Shift E */
                            insert(i, 62);
                            length++;
                        }
                        break;
                    default:
                        throw new OkapiException("Unexpected set " + set[i] + " at index " + i + ".");
                }
                i++;
            }
            i++;
        } while (i < set.length);

        /* Number compression has not been forgotten! It's handled below. */
        i = 0;
        do {
            if (set[i] == 6) {
                /* Number compression */
                int value = 0;
                for (j = 0; j < 9; j++) {
                    value *= 10;
                    value += (character[i + j] - '0');
                }
                character[i] = 31; /* NS */
                character[i + 1] = (value & 0x3f000000) >> 24;
                character[i + 2] = (value & 0xfc0000) >> 18;
                character[i + 3] = (value & 0x3f000) >> 12;
                character[i + 4] = (value & 0xfc0) >> 6;
                character[i + 5] = (value & 0x3f);
                i += 6;
                for (j = i; j < 140; j++) {
                    set[j] = set[j + 3];
                    character[j] = character[j + 3];
                }
                length -= 3;
            } else {
                i++;
            }
        } while (i < set.length);

        /* Inject ECI codes to beginning of data, according to Table 3 */
        if (eciMode != 3) {
            insert(0, 27); // ECI

            if ((eciMode >= 0) && (eciMode <= 31)) {
                insert(1, eciMode & 0x1F);
                length += 2;
            }

            if ((eciMode >= 32) && (eciMode <= 1023)) {
                insert(1, 0x20 + (eciMode >> 6));
                insert(2, eciMode & 0x3F);
                length += 3;
            }

            if ((eciMode >= 1024) && (eciMode <= 32767)) {
                insert(1, 0x30 + (eciMode >> 12));
                insert(2, (eciMode >> 6) & 0x3F);
                insert(3, eciMode & 0x3F);
                length += 4;
            }

            if ((eciMode >= 32768) && (eciMode <= 999999)) {
                insert(1, 0x38 + (eciMode >> 18));
                insert(2, (eciMode >> 12) & 0x3F);
                insert(3, (eciMode >> 6) & 0x3F);
                insert(4, eciMode & 0x3F);
                length += 5;
            }
        }

        /* Make sure we haven't exceeded the maximum data length. */
        int maxLength;
        if (mode == 2 || mode == 3) {
            maxLength = 84;
        } else if (mode == 4 || mode == 6) {
            maxLength = 93;
        } else if (mode == 5) {
            maxLength = 77;
        } else {
            maxLength = 0; // impossible
        }
        if (length > maxLength) {
            throw new OkapiException("Input data too long");
        }
    }
83194
protected void check (File source, String mname, int mline, String fname, int fline)
        throws IOException
    {
        if (mline == -1 && fline != -1) {
            throw new IOException(
                "Found " + fname + " marker (at line " + (fline+1) + ") but no " + mname +
                " marker in '" + source + "'.");
        }
    }
1232089
private int readChar()
    throws IOException
  {
    Reader readEncoding = _readEncoding;

    if (readEncoding == null)
      return read();
    else {
      if (readEncoding.read(_charBuffer, 0, 1) == 1) {
        return _charBuffer[0];
      }
      else {
        return -1;
      }
    }
  }