public void DoTest(StringBuilder failQueries)
 {
     bool pass = false;
     SrndQuery lq = null;
     try
     {
         lq = Parser.QueryParser.Parse(queryText);
         if (verbose)
         {
             Console.WriteLine("Query: " + queryText + "\nParsed as: " + lq.ToString());
         }
     }
     catch (ParseException e)
     {
         if (verbose)
         {
             Console.WriteLine("Parse exception for query:\n"
                               + queryText + "\n"
                               + e.Message);
         }
         pass = true;
     }
     if (!pass)
     {
         failQueries.append(queryText);
         failQueries.append("\nParsed as: ");
         failQueries.append(lq.toString());
         failQueries.append("\n");
     }
 }
Example #2
0
    // A1: going in reverse order, detect each word to append to the new string
    public String reverseWords(String a)
    {
        if (a == null || a.length() == 0) return a;

        StringBuilder b = new StringBuilder();

        int end = -1;
        int start = -1;
        int i = a.length()-1;

        while (i >= 0)
        {
            while (i >= 0 && a.charAt(i) == ' ') i--;
            end = i;

            while (i >= 0 && a.charAt(i) != ' ') i--;
            start = i;

            if (start < end) {
                if (b.length() > 0) b.append(' ');
                b.append(a.substring(start+1, end+1));
            }
        }

        return b.toString();
    }
Example #3
0
	/* XXX Called from Preprocessor [ugly]. */
	internal static void escape(StringBuilder buf, string cs) {
	    if (cs == null)
	    {
	        return;
	    }
		for (int i = 0; i < cs.length(); i++) {
			char	c = cs.charAt(i);
			switch (c) {
				case '\\':
					buf.append("\\\\");
					break;
				case '"':
					buf.append("\\\"");
					break;
				case '\n':
					buf.append("\\n");
					break;
				case '\r':
					buf.append("\\r");
					break;
				default:
					buf.append(c);
                    break;
			}
		}
	}
 /**
  * Returns the message string of the DuplicateFormatFlagsException.
  *
  * @return the message string of the DuplicateFormatFlagsException.
  */
 public override String getMessage()
 {
     StringBuilder buffer = new StringBuilder();
     buffer.append("Flags of the DuplicateFormatFlagsException is'");
     buffer.append(flags);
     buffer.append("'");
     return buffer.toString();
 }
Example #5
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.append("[");
            sb.append(getAgentLocation());
            sb.append(", ");
            sb.append(getLocationState());
            sb.append("]");

            return sb.ToString();
        }
Example #6
0
	private void concat(StringBuilder buf, Argument arg) {
		Iterator<Token>	it = arg.iterator();
		while (it.hasNext()) {
			Token	tok = it.next();
			buf.append(tok.getText());
		}
	}
 public static String toASCIILowerCase(String s)
 {
     int len = s.length();
     StringBuilder buffer = new StringBuilder(len);
     for (int i = 0; i < len; i++)
     {
         char c = s.charAt(i);
         if ('A' <= c && c <= 'Z')
         {
             buffer.append((char)(c + ('a' - 'A')));
         }
         else
         {
             buffer.append(c);
         }
     }
     return buffer.toString();
 }
        internal const String encoding = "utf-8"; //$NON-NLS-1$

        #endregion Fields

        #region Methods

        /**
         * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
         * and legal characters are converted into their hexidecimal value prepended
         * by '%'.
         * <p>
         * For example: '#' -> %23
         * Other characters, which are unicode chars that are not US-ASCII, and are
         * not ISO Control or are not ISO Space chars, are preserved.
         * <p>
         * Called from {@code URI.quoteComponent()} (for multiple argument
         * constructors)
         *
         * @param s
         *            java.lang.String the string to be converted
         * @param legal
         *            java.lang.String the characters allowed to be preserved in the
         *            string s
         * @return java.lang.String the converted string
         */
        internal static String quoteIllegal(String s, String legal)
        {
            //throws UnsupportedEncodingException {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if ((ch >= 'a' && ch <= 'z')
                        || (ch >= 'A' && ch <= 'Z')
                        || (ch >= '0' && ch <= '9')
                        || legal.indexOf(ch) > -1
                        || (ch > 127 && !java.lang.Character.isSpaceChar(ch) && !java.lang.Character
                                .isISOControl(ch))) {
                    buf.append(ch);
                } else {
                    byte[] bytes = new String(new char[] { ch }).getBytes(encoding);
                    for (int j = 0; j < bytes.Length; j++) {
                        buf.append('%');
                        buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                        buf.append(digits.charAt(bytes[j] & 0xf));
                    }
                }
            }
            return buf.toString();
        }
 private KeyValuePair<List<List<string>>, string> generateFileInput(int count, string fieldDelimiter, bool hasWeights, bool hasPayloads)
 {
     List<List<string>> entries = new List<List<string>>();
     StringBuilder sb = new StringBuilder();
     bool hasPayload = hasPayloads;
     for (int i = 0; i < count; i++)
     {
         if (hasPayloads)
         {
             hasPayload = (i == 0) ? true : Random().nextBoolean();
         }
         KeyValuePair<List<string>, string> entrySet = GenerateFileEntry(fieldDelimiter, (!hasPayloads && hasWeights) ? Random().nextBoolean() : hasWeights, hasPayload);
         entries.Add(entrySet.Key);
         sb.append(entrySet.Value);
     }
     return new KeyValuePair<List<List<string>>, string>(entries, sb.toString());
 }
 private KeyValuePair<List<string>, string> GenerateFileEntry(string fieldDelimiter, bool hasWeight, bool hasPayload)
 {
     List<string> entryValues = new List<string>();
     StringBuilder sb = new StringBuilder();
     string term = TestUtil.RandomSimpleString(Random(), 1, 300);
     sb.append(term);
     entryValues.Add(term);
     if (hasWeight)
     {
         sb.append(fieldDelimiter);
         long weight = TestUtil.NextLong(Random(), long.MinValue, long.MaxValue);
         sb.append(weight);
         entryValues.Add(weight.ToString());
     }
     if (hasPayload)
     {
         sb.append(fieldDelimiter);
         string payload = TestUtil.RandomSimpleString(Random(), 1, 300);
         sb.append(payload);
         entryValues.Add(payload);
     }
     sb.append("\n");
     return new KeyValuePair<List<string>, string>(entryValues, sb.toString());
 }
Example #11
0
        /// <summary>
        /// Encode this name as a URI according to the NDN URI Scheme.
        /// </summary>
        ///
        /// <param name="includeScheme">which is normally the case where toUri() is used for display.</param>
        /// <returns>The URI string.</returns>
        public String toUri(bool includeScheme)
        {
            if ((components_.Count==0))
                return (includeScheme) ? "ndn:/" : "/";

            StringBuilder result = new StringBuilder();
            if (includeScheme)
                result.append("ndn:");
            for (int i = 0; i < components_.Count; ++i) {
                result.append("/");
                get(i).toEscapedString(result);
            }

            return result.toString();
        }
Example #12
0
 /// <summary>
 /// Write this component value to result, escaping characters according to
 /// the NDN URI Scheme. This also adds "..." to a value with zero or more ".".
 /// This adds a type code prefix as needed, such as "sha256digest=".
 /// </summary>
 ///
 /// <param name="result">The StringBuffer to write to.</param>
 public void toEscapedString(StringBuilder result)
 {
     if (type_ == net.named_data.jndn.Name.Component.ComponentType.IMPLICIT_SHA256_DIGEST) {
         result.append("sha256digest=");
         net.named_data.jndn.util.Blob.toHex(value_.buf(), result);
     } else
         net.named_data.jndn.Name.toEscapedString(value_.buf(), result);
 }
Example #13
0
 /// <summary>
 /// Write the value to result, escaping characters according to the NDN URI
 /// Scheme.
 /// This also adds "..." to a value with zero or more ".".
 /// This does not add a type code prefix such as "sha256digest=".
 /// </summary>
 ///
 /// <param name="value"></param>
 /// <param name="result">The StringBuffer to write to.</param>
 public static void toEscapedString(ByteBuffer value_ren, StringBuilder result)
 {
     bool gotNonDot = false;
     for (int i = value_ren.position(); i < value_ren.limit(); ++i) {
         if (value_ren.get(i) != 0x2e) {
             gotNonDot = true;
             break;
         }
     }
     if (!gotNonDot) {
         // Special case for component of zero or more periods.  Add 3 periods.
         result.append("...");
         for (int i_0 = value_ren.position(); i_0 < value_ren.limit(); ++i_0)
             result.append('.');
     } else {
         for (int i_1 = value_ren.position(); i_1 < value_ren.limit(); ++i_1) {
             int x = ((int) value_ren.get(i_1) & 0xff);
             // Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
             if (x >= 0x30 && x <= 0x39 || x >= 0x41 && x <= 0x5a
                     || x >= 0x61 && x <= 0x7a || x == 0x2b || x == 0x2d
                     || x == 0x2e || x == 0x5f)
                 result.append((char) x);
             else {
                 result.append('%');
                 if (x < 16)
                     result.append('0');
                 result.append(ILOG.J2CsMapping.Util.IlNumber.ToString(x,16).ToUpper());
             }
         }
     }
 }
Example #14
0
 protected internal virtual String convertPattern(String template, String fromChars, String toChars,
         bool check)
 {
     if (!check && fromChars.equals(toChars)) {
         return template;
     }
     bool quote = false;
     StringBuilder output = new StringBuilder();
     int length = template.length();
     for (int i = 0; i < length; i++) {
         int index;
         char next = template.charAt(i);
         if (next == '\'') {
             quote = !quote;
         }
         if (!quote && (index = fromChars.indexOf(next)) != -1) {
             output.append(toChars.charAt(index));
         } else if (check
                 && !quote
                 && ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
             // text.05=Invalid pattern char {0} in {1}
             throw new java.lang.IllegalArgumentException("Invalid pattern char "+next+" in "+ template); //$NON-NLS-1$
         } else {
             output.append(next);
         }
     }
     if (quote) {
         // text.04=Unterminated quote
         throw new java.lang.IllegalArgumentException("Unterminated quote"); //$NON-NLS-1$
     }
     return output.toString();
 }
 public String toString() {
   StringBuilder buffer = new StringBuilder();
   buffer.append("mockFs{files:[");
   for(int i=0; i < files.size(); ++i) {
     if (i != 0) {
       buffer.append(", ");
     }
     buffer.append(files.get(i));
   }
   buffer.append("]}");
   return buffer.toString();
 }
Example #16
0
 public String readLine()
 {
     //throws IOException {
     StringBuilder line = new StringBuilder(80); // Typical line length
     bool foundTerminator = false;
     while (true) {
         int nextByte = inJ.read();
         switch (nextByte) {
             case -1:
                 if (line.Length == 0 && !foundTerminator) {
                     return null;
                 }
                 return line.toString();
             case (byte) '\r':
                 if (foundTerminator) {
                     ((PushbackInputStream) inJ).unread(nextByte);
                     return line.toString();
                 }
                 foundTerminator = true;
                 /* Have to be able to peek ahead one byte */
                 if (!(inJ is PushbackInputStream)) { //think Bug in Harmony, not test on class but on type required
                     inJ = new PushbackInputStream(inJ);
                 }
                 break;
             case (byte) '\n':
                 return line.toString();
             default:
                 if (foundTerminator) {
                     ((PushbackInputStream) inJ).unread(nextByte);
                     return line.toString();
                 }
                 line.append((char) nextByte);
                 break;
         }
     }
 }
Example #17
0
 /**
  * Returns a string containing a concise, human-readable description of the
  * receiver.
  *
  * @return a comma delimited list of the indices of all bits that are set.
  */
 public override String ToString()
 {
     StringBuilder sb = new StringBuilder(bits.Length / 2);
     int bitCount = 0;
     sb.append('{');
     bool comma = false;
     for (int i = 0; i < bits.Length; i++) {
         if (bits[i] == 0) {
             bitCount += ELM_SIZE;
             continue;
         }
         for (int j = 0; j < ELM_SIZE; j++) {
             if (((bits[i] & (TWO_N_ARRAY[j])) != 0)) {
                 if (comma) {
                     sb.append(", "); //$NON-NLS-1$
                 }
                 sb.append(bitCount);
                 comma = true;
             }
             bitCount++;
         }
     }
     sb.append('}');
     return sb.toString();
 }
Example #18
0
 /**
  * Returns the state of this tokenizer in a readable format.
  *
  * @return the current state of this tokenizer.
  */
 public override String ToString()
 {
     // Values determined through experimentation
     StringBuilder result = new StringBuilder();
     result.append("Token["); //$NON-NLS-1$
     switch (ttype) {
         case TT_EOF:
             result.append("EOF"); //$NON-NLS-1$
             break;
         case TT_EOL:
             result.append("EOL"); //$NON-NLS-1$
             break;
         case TT_NUMBER:
             result.append("n="); //$NON-NLS-1$
             result.append(nval);
             break;
         case TT_WORD:
             result.append(sval);
             break;
         default:
             if (ttype == TT_UNKNOWN || tokenTypes[ttype] == TOKEN_QUOTE) {
                 result.append(sval);
             } else {
                 result.append('\'');
                 result.append((char) ttype);
                 result.append('\'');
             }
             break;
     }
     result.append("], line "); //$NON-NLS-1$
     result.append(lineNumber);
     return result.toString();
 }
        private static void WriteAndReadAString()
        {
            // Write out a string whose UTF-8 encoding is quite possibly
            // longer than 65535 bytes
            int length = Random().nextInt(A_NUMBER_NEAR_65535) + 1;
            MemoryStream baos = new MemoryStream();
            StringBuilder testBuffer = new StringBuilder();
            for (int i = 0; i < length; i++)
                testBuffer.append((char)Random().Next());
            string testString = testBuffer.toString();
            DataOutputStream dos = new DataOutputStream(baos);
            dos.WriteUTF(testString);

            // Corrupt the data to produce malformed characters
            byte[] testBytes = baos.ToArray();
            int dataLength = testBytes.Length;
            int corruptions = Random().nextInt(MAX_CORRUPTIONS_PER_CYCLE);
            for (int i = 0; i < corruptions; i++)
            {
                int index = Random().nextInt(dataLength);
                testBytes[index] = (byte)Random().Next();
            }

            // Pay special attention to mangling the end to produce
            // partial characters at end
            testBytes[dataLength - 1] = (byte)Random().Next();
            testBytes[dataLength - 2] = (byte)Random().Next();

            // Attempt to decode the bytes back into a String
            MemoryStream bais = new MemoryStream(testBytes);
            DataInputStream dis = new DataInputStream(bais);
            dis.ReadUTF();
        }
        /**
         * Loop to encode a data packet nIterations times.
         * @param nIterations The number of iterations.
         * @param useComplex If true, use a large name, large content and all fields.
         * If false, use a small name, small content
         * and only required fields.
         * @param useCrypto If true, sign the data packet.  If false, use a blank
         * signature.
         * @param keyType KeyType.RSA or EC, used if useCrypto is true.
         * @param encoding Set encoding[0] to the wire encoding.
         * @return The number of seconds for all iterations.
         */
        private static double benchmarkEncodeDataSeconds(int nIterations, bool useComplex, bool useCrypto, KeyType keyType,
        Blob[] encoding)
        {
            Name name;
              Blob content;
              if (useComplex) {
            // Use a large name and content.
            name = new Name
              ("/ndn/ucla.edu/apps/lwndn-test/numbers.txt/%FD%05%05%E8%0C%CE%1D/%00");

            StringBuilder contentStream = new StringBuilder();
            int count = 1;
            contentStream.append(count++);
            while (contentStream.toString().Length < 1115)
              contentStream.append(" ").append(count++);
            content = new Blob(contentStream.toString());
              }
              else {
            // Use a small name and content.
            name = new Name("/test");
            content = new Blob("abc");
              }
              Name.Component finalBlockId =
            new Name.Component(new Blob(new byte[] { (byte)0 }));

              // Initialize the KeyChain storage in case useCrypto is true.
              MemoryIdentityStorage identityStorage = new MemoryIdentityStorage();
              MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage();
              KeyChain keyChain = new KeyChain
            (new IdentityManager(identityStorage, privateKeyStorage),
              new SelfVerifyPolicyManager(identityStorage));
              Name keyName = new Name("/testname/DSK-123");
              Name certificateName = keyName.getSubName(0, keyName.size() - 1).append
            ("KEY").append(keyName.get(-1)).append("ID-CERT").append("0");
              privateKeyStorage.setKeyPairForKeyName
              (keyName, KeyType.RSA, new ByteBuffer(DEFAULT_RSA_PUBLIC_KEY_DER),
            new ByteBuffer(DEFAULT_RSA_PRIVATE_KEY_DER));

              Blob signatureBits = new Blob(new byte[256]);
              Blob emptyBlob = new Blob(new byte[0]);

              double start = getNowSeconds();
              for (int i = 0; i < nIterations; ++i) {
            Data data = new Data(name);
            data.setContent(content);
            if (useComplex) {
              data.getMetaInfo().setFreshnessPeriod(30000);
              data.getMetaInfo().setFinalBlockId(finalBlockId);
            }

            if (useCrypto)
              // This sets the signature fields.
              keyChain.sign(data, certificateName);
            else {
              // Imitate IdentityManager.signByCertificate to set up the signature
              //   fields, but don't sign.
              KeyLocator keyLocator = new KeyLocator();
              keyLocator.setType(KeyLocatorType.KEYNAME);
              keyLocator.setKeyName(certificateName);
              Sha256WithRsaSignature sha256Signature =
            (Sha256WithRsaSignature)data.getSignature();
              sha256Signature.setKeyLocator(keyLocator);
              sha256Signature.setSignature(signatureBits);
            }

            encoding[0] = data.wireEncode();
              }
              double finish = getNowSeconds();

              return finish - start;
        }
Example #21
0
        /**
         * Parses the next token from this tokenizer's source stream or reader. The
         * type of the token is stored in the {@code ttype} field, additional
         * information may be stored in the {@code nval} or {@code sval} fields.
         *
         * @return the value of {@code ttype}.
         * @throws IOException
         *             if an I/O error occurs while parsing the next token.
         */
        public virtual int nextToken()
        {
            // throws IOException {
            if (pushBackToken) {
                pushBackToken = false;
                if (ttype != TT_UNKNOWN) {
                    return ttype;
                }
            }
            sval = null; // Always reset sval to null
            int currentChar = peekChar == -2 ? read() : peekChar;

            if (lastCr && currentChar == '\n') {
                lastCr = false;
                currentChar = read();
            }
            if (currentChar == -1) {
                return (ttype = TT_EOF);
            }

            byte currentType = currentChar > 255 ? TOKEN_WORD
                    : tokenTypes[currentChar];
            while ((currentType & TOKEN_WHITE) != 0) {
                /**
                 * Skip over white space until we hit a new line or a real token
                 */
                if (currentChar == '\r') {
                    lineNumber++;
                    if (isEOLSignificant) {
                        lastCr = true;
                        peekChar = -2;
                        return (ttype = TT_EOL);
                    }
                    if ((currentChar = read()) == '\n') {
                        currentChar = read();
                    }
                } else if (currentChar == '\n') {
                    lineNumber++;
                    if (isEOLSignificant) {
                        peekChar = -2;
                        return (ttype = TT_EOL);
                    }
                    currentChar = read();
                } else {
                    // Advance over this white space character and try again.
                    currentChar = read();
                }
                if (currentChar == -1) {
                    return (ttype = TT_EOF);
                }
                currentType = currentChar > 255 ? TOKEN_WORD
                        : tokenTypes[currentChar];
            }

            /**
             * Check for digits before checking for words since digits can be
             * contained within words.
             */
            if ((currentType & TOKEN_DIGIT) != 0) {
                StringBuilder digits = new StringBuilder(20);
                bool haveDecimal = false, checkJustNegative = currentChar == '-';
                while (true) {
                    if (currentChar == '.') {
                        haveDecimal = true;
                    }
                    digits.append((char) currentChar);
                    currentChar = read();
                    if ((currentChar < '0' || currentChar > '9')
                            && (haveDecimal || currentChar != '.')) {
                        break;
                    }
                }
                peekChar = currentChar;
                if (checkJustNegative && digits.Length == 1) {
                    // Didn't get any other digits other than '-'
                    return (ttype = '-');
                }
                try {
                    nval = java.lang.Double.valueOf(digits.toString()).doubleValue();
                } catch (java.lang.NumberFormatException e) {
                    // Unsure what to do, will write test.
                    nval = 0;
                }
                return (ttype = TT_NUMBER);
            }
            // Check for words
            if ((currentType & TOKEN_WORD) != 0) {
                StringBuilder word = new StringBuilder(20);
                while (true) {
                    word.append((char) currentChar);
                    currentChar = read();
                    if (currentChar == -1
                            || (currentChar < 256 && (tokenTypes[currentChar] & (TOKEN_WORD | TOKEN_DIGIT)) == 0)) {
                        break;
                    }
                }
                peekChar = currentChar;
                sval = forceLowercase ? word.toString().ToLower() : word
                        .toString();
                return (ttype = TT_WORD);
            }
            // Check for quoted character
            if (currentType == TOKEN_QUOTE) {
                int matchQuote = currentChar;
                StringBuilder quoteString = new StringBuilder();
                int peekOne = read();
                while (peekOne >= 0 && peekOne != matchQuote && peekOne != '\r'
                        && peekOne != '\n') {
                    bool readPeek = true;
                    if (peekOne == '\\') {
                        int c1 = read();
                        // Check for quoted octal IE: \377
                        if (c1 <= '7' && c1 >= '0') {
                            int digitValue = c1 - '0';
                            c1 = read();
                            if (c1 > '7' || c1 < '0') {
                                readPeek = false;
                            } else {
                                digitValue = digitValue * 8 + (c1 - '0');
                                c1 = read();
                                // limit the digit value to a byte
                                if (digitValue > 037 || c1 > '7' || c1 < '0') {
                                    readPeek = false;
                                } else {
                                    digitValue = digitValue * 8 + (c1 - '0');
                                }
                            }
                            if (!readPeek) {
                                // We've consumed one to many
                                quoteString.append((char) digitValue);
                                peekOne = c1;
                            } else {
                                peekOne = digitValue;
                            }
                        } else {
                            switch (c1) {
                                case 'a':
                                    peekOne = 0x7;
                                    break;
                                case 'b':
                                    peekOne = 0x8;
                                    break;
                                case 'f':
                                    peekOne = 0xc;
                                    break;
                                case 'n':
                                    peekOne = 0xA;
                                    break;
                                case 'r':
                                    peekOne = 0xD;
                                    break;
                                case 't':
                                    peekOne = 0x9;
                                    break;
                                case 'v':
                                    peekOne = 0xB;
                                    break;
                                default:
                                    peekOne = c1;
                                    break;
                            }
                        }
                    }
                    if (readPeek) {
                        quoteString.append((char) peekOne);
                        peekOne = read();
                    }
                }
                if (peekOne == matchQuote) {
                    peekOne = read();
                }
                peekChar = peekOne;
                ttype = matchQuote;
                sval = quoteString.toString();
                return ttype;
            }
            // Do comments, both "//" and "/*stuff*/"
            if (currentChar == '/' && (slashSlashCommentsJ || slashStarCommentsJ)) {
                if ((currentChar = read()) == '*' && slashStarCommentsJ) {
                    int peekOne = read();
                    while (true) {
                        currentChar = peekOne;
                        peekOne = read();
                        if (currentChar == -1) {
                            peekChar = -1;
                            return (ttype = TT_EOF);
                        }
                        if (currentChar == '\r') {
                            if (peekOne == '\n') {
                                peekOne = read();
                            }
                            lineNumber++;
                        } else if (currentChar == '\n') {
                            lineNumber++;
                        } else if (currentChar == '*' && peekOne == '/') {
                            peekChar = read();
                            return nextToken();
                        }
                    }
                } else if (currentChar == '/' && slashSlashCommentsJ) {
                    // Skip to EOF or new line then return the next token
                    while ((currentChar = read()) >= 0 && currentChar != '\r'
                            && currentChar != '\n') {
                        // Intentionally empty
                    }
                    peekChar = currentChar;
                    return nextToken();
                } else if (currentType != TOKEN_COMMENT) {
                    // Was just a slash by itself
                    peekChar = currentChar;
                    return (ttype = '/');
                }
            }
            // Check for comment character
            if (currentType == TOKEN_COMMENT) {
                // Skip to EOF or new line then return the next token
                while ((currentChar = read()) >= 0 && currentChar != '\r'
                        && currentChar != '\n') {
                    // Intentionally empty
                }
                peekChar = currentChar;
                return nextToken();
            }

            peekChar = read();
            return (ttype = currentChar);
        }
Example #22
0
 /**
  * Other characters, which are Unicode chars that are not US-ASCII, and are
  * not ISO Control or are not ISO Space chars are not preserved. They are
  * converted into their hexidecimal value prepended by '%'.
  * <p>
  * For example: Euro currency symbol -> "%E2%82%AC".
  * <p>
  * Called from URI.toASCIIString()
  *
  * @param s
  *            java.lang.String the string to be converted
  * @return java.lang.String the converted string
  */
 static String encodeOthers(String s)
 {
     //throws UnsupportedEncodingException {
     StringBuilder buf = new StringBuilder();
     for (int i = 0; i < s.length(); i++) {
         char ch = s.charAt(i);
         if (ch <= 127) {
             buf.append(ch);
         } else {
             byte[] bytes = new String(new char[] { ch }).getBytes(encoding);
             for (int j = 0; j < bytes.Length; j++) {
                 buf.append('%');
                 buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                 buf.append(digits.charAt(bytes[j] & 0xf));
             }
         }
     }
     return buf.toString();
 }
Example #23
0
        /**
         * Decodes the string argument which is assumed to be encoded in the {@code
         * x-www-form-urlencoded} MIME content type using the UTF-8 encoding scheme.
         * <p>
         *'%' and two following hex digit characters are converted to the
         * equivalent byte value. All other characters are passed through
         * unmodified.
         * <p>
         * e.g. "A%20B%20C %24%25" -> "A B C $%"
         * <p>
         * Called from URI.getXYZ() methods
         *
         * @param s
         *            java.lang.String The encoded string.
         * @return java.lang.String The decoded version.
         */
        static String decode(String s)
        {
            //throws UnsupportedEncodingException {

            StringBuilder result = new StringBuilder();
            java.io.ByteArrayOutputStream outJ = new java.io.ByteArrayOutputStream();
            for (int i = 0; i < s.length();) {
                char c = s.charAt(i);
                if (c == '%') {
                    outJ.reset();
                    do {
                        if (i + 2 >= s.length()) {
                            throw new java.lang.IllegalArgumentException("Incomplete % sequence at: "+ i); //$NON-NLS-1$
                        }
                        int d1 = java.lang.Character.digit(s.charAt(i + 1), 16);
                        int d2 = java.lang.Character.digit(s.charAt(i + 2), 16);
                        if (d1 == -1 || d2 == -1) {
                            throw new java.lang.IllegalArgumentException("Invalid % sequence ("+s.substring(i, i + 3)+") at: "+java.lang.StringJ.valueOf(i));
                        }
                        outJ.write((byte) ((d1 << 4) + d2));
                        i += 3;
                    } while (i < s.length() && s.charAt(i) == '%');
                    result.append(outJ.toString(encoding));
                    continue;
                }
                result.append(c);
                i++;
            }
            return result.toString();
        }
Example #24
0
        /// <summary>
        /// Encode the name according to the "NDN URI Scheme".  If there are interest
        /// selectors, append "?" and added the selectors as a query string.  For
        /// example "/test/name?ndn.ChildSelector=1".
        /// </summary>
        ///
        /// <returns>The URI string.</returns>
        /// @note This is an experimental feature.  See the API docs for more detail at
        /// http://named-data.net/doc/ndn-ccl-api/interest.html#interest-touri-method .
        public String toUri()
        {
            StringBuilder selectors = new StringBuilder();

            if (minSuffixComponents_ >= 0)
                selectors.append("&ndn.MinSuffixComponents=").append(
                        minSuffixComponents_);
            if (maxSuffixComponents_ >= 0)
                selectors.append("&ndn.MaxSuffixComponents=").append(
                        maxSuffixComponents_);
            if (childSelector_ >= 0)
                selectors.append("&ndn.ChildSelector=").append(childSelector_);
            selectors.append("&ndn.MustBeFresh=").append((mustBeFresh_) ? 1 : 0);
            if (interestLifetimeMilliseconds_ >= 0)
                selectors.append("&ndn.InterestLifetime=").append(
                        (long) Math.Round(interestLifetimeMilliseconds_,MidpointRounding.AwayFromZero));
            if (nonce_.size() > 0) {
                selectors.append("&ndn.Nonce=");
                net.named_data.jndn.Name.toEscapedString(nonce_.buf(), selectors);
            }
            if (getExclude().size() > 0)
                selectors.append("&ndn.Exclude=").append(getExclude().toUri());

            StringBuilder result = new StringBuilder();

            result.append(getName().toUri());
            String selectorsString = selectors.toString();
            if (selectorsString.Length > 0)
                // Replace the first & with ?.
                result.append("?").append(selectorsString.Substring(1));

            return result.toString();
        }
 /**
  * Makes a bunch of single-char tokens (the max # unique terms will at most be 26).
  * puts the # unique terms into expected, to be checked against the norm.
  */
 private string AddValue()
 {
     StringBuilder sb = new StringBuilder();
     HashSet<string> terms = new HashSet<string>();
     int num = TestUtil.NextInt(Random(), 0, 255);
     for (int i = 0; i < num; i++)
     {
         sb.append(' ');
         char term = (char)TestUtil.NextInt(Random(), 'a', 'z');
         sb.append(term);
         terms.add("" + term);
     }
     expected.Add(terms.size());
     return sb.toString();
 }
Example #26
0
 /// <summary>
 /// Write a hex string of the contents of buffer from position to limit to the
 /// output.
 /// </summary>
 ///
 /// <param name="buffer">The buffer.</param>
 /// <returns>A string of hex bytes.</returns>
 /// <param name="output">The StringBuffer to write to.</param>
 public static void toHex(ByteBuffer buffer, StringBuilder output)
 {
     for (int i = buffer.position(); i < buffer.limit(); ++i) {
         String hex = ILOG.J2CsMapping.Util.IlNumber.ToString((int) buffer.get(i) & 0xff,16);
         if (hex.Length <= 1)
             // Append the leading zero.
             output.append("0");
         output.append(hex);
     }
 }
 /// <summary>
 /// This method is used to convert the provided value into an XML
 /// usable format. This is used in the serialization process when
 /// there is a need to convert a field value in to a string so
 /// that that value can be written as a valid XML entity.
 /// </summary>
 /// <param name="value">
 /// this is the value to be converted to a string
 /// </param>
 /// <returns>
 /// this is the string representation of the given value
 /// </returns>
 public String Write(Object value, int length) {
    StringBuilder text = new StringBuilder(length);
    for(int i = 0; i < length; i++) {
       Object entry = Array.get(value, i);
       if(entry != null) {
          text.append(entry);
       }
    }
    return text.toString();
 }
	    /**
	     * Parses <code>source</code> for special double values.  These values
	     * include Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.
	     *
	     * @param source the string to parse
	     * @param value the special value to parse.
	     * @param pos input/ouput parsing parameter.
	     * @return the special number.
	     */
	    private static Number parseNumber(String source, double value,
	                                      ParsePosition pos) {
	        Number ret = null;
	
	        StringBuilder sb = new StringBuilder();
	        sb.append('(');
	        sb.append(value);
	        sb.append(')');
	
	        int n = sb.length();
	        int startIndex = pos.getIndex();
	        int endIndex = startIndex + n;
	        if (endIndex < source.length()) {
	            if (source.substring(startIndex, endIndex).compareTo(sb.toString()) == 0) {
	                ret = Double.valueOf(value);
	                pos.setIndex(endIndex);
	            }
	        }
	
	        return ret;
	    }
Example #29
0
	private void mHereDocContents()
	{
		EnterRule_HereDocContents();
		EnterRule("HereDocContents", 121);
		TraceIn("HereDocContents", 121);
		try
		{
			// C:\\Users\\exKAZUu\\Projects\\Code2Xml\\Code2Xml.Core\\Generators\\ANTLRv3\\Php\\Php.g:736:2: ()
			DebugEnterAlt(1);
			// C:\\Users\\exKAZUu\\Projects\\Code2Xml\\Code2Xml.Core\\Generators\\ANTLRv3\\Php\\Php.g:736:4: 
			{
			DebugLocation(736, 4);
			if (state.backtracking == 0)
			{

						// Please see also Code2Xml.Languages.ANTLRv3.Core.ExtensionForParser
						var sb = new StringBuilder();
						while (input.LA(1) != '\n') {
							sb.append((char)input.LA(1));
							input.consume();
						}
						input.consume();
						var hereDocName = sb.toString().TrimEnd();
						var hdnl = hereDocName.length();
						while (true) {
							var matchEnd = true;
							for (int i = 0; i < hdnl; i++) {
								if (input.LA(1) != hereDocName.charAt(i)) {
									matchEnd = false;
									break;
								}
								input.consume();
							}
							if (matchEnd == false) {
								while (input.LA(1) != '\n') {
									input.consume();
								}
								input.consume();
							} else {
								break;
							}
						}
					
			}

			}

		}
		finally
		{
			TraceOut("HereDocContents", 121);
			LeaveRule("HereDocContents", 121);
			LeaveRule_HereDocContents();
		}
	}
Example #30
0
        /// <summary>
        /// Encode this Exclude with elements separated by "," and Exclude.Type.ANY
        /// shown as "///".
        /// </summary>
        ///
        /// <returns>the URI string</returns>
        public String toUri()
        {
            if ((entries_.Count==0))
                return "";

            StringBuilder result = new StringBuilder();
            for (int i = 0; i < entries_.Count; ++i) {
                if (i > 0)
                    result.append(",");

                if (get(i).getType() == net.named_data.jndn.Exclude.Type.ANY)
                    result.append("*");
                else
                    get(i).getComponent().toEscapedString(result);
            }

            return result.toString();
        }