append() private method

private append ( char par0 ) : global::java.lang.Appendable
par0 char
return global::java.lang.Appendable
Ejemplo n.º 1
0
		private string join(Iterable<String> items, int limit) {
			StringBuilder sb = new StringBuilder();
			int count = 0;
			foreach (string item in items) {
				if (count > 0)
					sb.append(", ");
				sb.append(item);
				if (limit > 0 && count == limit)
					break;
				count++;
			}
			return sb.toString();
		}
	public static string test() {
		var sb = new StringBuilder();
		var first = true;
		foreach (var i in range(0, 5)) {
			if (first) {
				first = false;
			} else {
				sb.append(", ");
			}
			sb.append(i);
		}		
		return sb.toString();
	}
Ejemplo n.º 3
0
	public string method() {
		var sb = new StringBuilder();
		var it = power(2, 8).iterator();
		var first = true;
		while (it.hasNext()) {
			if (first) {
				first = false;
			} else {
				sb.append(", ");
			}
			sb.append("" + it.nextInt());
		}
		return sb.toString();	
	}
Ejemplo n.º 4
0
		/// <summary>Returns a string containing the tokens joined by delimiters.</summary>
		/// <remarks>Returns a string containing the tokens joined by delimiters.</remarks>
		/// <param name="tokens">
		/// an array objects to be joined. Strings will be formed from
		/// the objects by calling object.toString().
		/// </param>
		public static string join (CharSequence delimiter, Iterable<CharSequence> tokens)
		{
			StringBuilder sb = new StringBuilder ();
			bool firstTime = true;
			foreach (object token in Sharpen.IterableProxy.Create(tokens)) {
				if (firstTime) {
					firstTime = false;
				} else {
					sb.append (delimiter);
				}
				sb.append (token);
			}
			return sb.ToString ();
		}
 public static String quoteReplacement(String s)
 {
     if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1))
     return s;
     StringBuilder sb = new StringBuilder();
     for (int i=0; i<s.length(); i++) {
     char c = s.charAt(i);
     if (c == '\\' || c == '$') {
         sb.append('\\');
     }
     sb.append(c);
     }
     return sb.toString();
 }
Ejemplo n.º 6
0
	public static string method(params string[] values) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < sizeof(values); i++) {
			sb.append(values[i]);
		}
		return sb.toString();
	}
 private void appendSubsequentLocalePart(String subsequentLocalePart, StringBuilder fullLocale)
 {
     if (subsequentLocalePart.length() > 0)
     {
         fullLocale.append('_').append(subsequentLocalePart);
     }
 }
        /**
         * Gets the name of the file that contains the mapping data for the {@code countryCallingCode} in
         * the language specified.
         *
         * @param countryCallingCode  the country calling code of phone numbers which the data file
         *     contains
         * @param language  two-letter lowercase ISO language codes as defined by ISO 639-1
         * @param script  four-letter titlecase (the first letter is uppercase and the rest of the letters
         *     are lowercase) ISO script codes as defined in ISO 15924
         * @param region  two-letter uppercase ISO country codes as defined by ISO 3166-1
         * @return  the name of the file, or empty string if no such file can be found
         */
        internal String getFileName(int countryCallingCode, String language, String script, String region)
        {
            if (language.length() == 0)
            {
                return("");
            }
            int index = Arrays.binarySearch(countryCallingCodes, countryCallingCode);

            if (index < 0)
            {
                return("");
            }
            Set <String> setOfLangs = availableLanguages.get(index);

            if (setOfLangs.size() > 0)
            {
                String languageCode = findBestMatchingLanguageCode(setOfLangs, language, script, region);
                if (languageCode.length() > 0)
                {
                    StringBuilder fileName = new StringBuilder();
                    fileName.append(countryCallingCode).append('_').append(languageCode);
                    return(fileName.toString());
                }
            }
            return("");
        }
    public static string test(string s1, string s2)
    {
        SB sb = new SB(s1);

        sb.append(s2);
        return(sb.toString());
    }
Ejemplo n.º 10
0
        public override string ToString()
        {
            java.lang.StringBuilder builder = new java.lang.StringBuilder(GetClassName());
            builder.append(": ").append(Message);

            if (innerException != null)
            {
                builder.append(" ---> ").append(innerException.ToString())
                .append(Environment.NewLine).append(Local.GetText("  --- End of inner exception stack trace ---"));
            }
            if (StackTrace != null)
            {
                builder.append(Environment.NewLine).append(StackTrace);
            }
            return(builder.ToString());
        }
Ejemplo n.º 11
0
        private boolean createFormattingTemplate(NumberFormat format)
        {
            String numberPattern = format.getPattern();

            // The formatter doesn't format numbers when numberPattern contains "|", e.g.
            // (20|3)\d{4}. In those cases we quickly return.
            if (numberPattern.indexOf('|') != -1)
            {
                return(false);
            }

            // Replace anything in the form of [..] with \d
            numberPattern = CHARACTER_CLASS_PATTERN.matcher(numberPattern).replaceAll("\\\\d");

            // Replace any standalone digit (not the one in d{}) with \d
            numberPattern = STANDALONE_DIGIT_PATTERN.matcher(numberPattern).replaceAll("\\\\d");
            formattingTemplate.setLength(0);
            String tempTemplate = getFormattingTemplate(numberPattern, format.getFormat());

            if (tempTemplate.length() > 0)
            {
                formattingTemplate.append(tempTemplate);
                return(true);
            }
            return(false);
        }
	public string method() {
		var sb = new StringBuilder();
		var it = strings().iterator();
		while (it.hasNext()) {
			sb.append(it.next());
		}
		return sb.toString();		
	}
        /**
         * Returns a string representing the data in this class. The string contains one line for each
         * country calling code. The country calling code is followed by a '|' and then a list of
         * comma-separated languages sorted in ascending order.
         */
        public String toString()
        {
            StringBuilder output = new StringBuilder();

            for (int i = 0; i < numOfEntries; i++)
            {
                output.append(countryCallingCodes[i]);
                output.append('|');
                SortedSet <String> sortedSetOfLangs = new TreeSet <String>(availableLanguages.get(i));
                foreach (String lang in sortedSetOfLangs)
                {
                    output.append(lang);
                    output.append(',');
                }
                output.append('\n');
            }
            return(output.toString());
        }
Ejemplo n.º 14
0
 public override string format(LogRecord logrecord)
 {
     var stringbuilder = new StringBuilder();
     Level level = logrecord.getLevel();
     if (level == Level.FINEST)
     {
         stringbuilder.append("[FINEST] ");
     }
     else if (level == Level.FINER)
     {
         stringbuilder.append("[FINER] ");
     }
     else if (level == Level.FINE)
     {
         stringbuilder.append("[FINE] ");
     }
     else if (level == Level.INFO)
     {
         stringbuilder.append("[INFO] ");
     }
     else if (level == Level.WARNING)
     {
         stringbuilder.append("[WARNING] ");
     }
     else if (level == Level.SEVERE)
     {
         stringbuilder.append("[SEVERE] ");
     }
     else if (level == Level.SEVERE)
     {
         stringbuilder.append(
             (new StringBuilder()).append("[").append(level.getLocalizedName()).append("] ").toString());
     }
     stringbuilder.append(logrecord.getMessage());
     stringbuilder.append('\n');
     var throwable = logrecord.getThrown() as Throwable;
     if (throwable != null)
     {
         var stringwriter = new StringWriter();
         throwable.printStackTrace(new PrintWriter(stringwriter));
         stringbuilder.append(stringwriter.toString());
     }
     return stringbuilder.toString();
 }
Ejemplo n.º 15
0
        public static String quoteReplacement(String s)
        {
            if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1))
            {
                return(s);
            }
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < s.length(); i++)
            {
                char c = s.charAt(i);
                if (c == '\\' || c == '$')
                {
                    sb.append('\\');
                }
                sb.append(c);
            }
            return(sb.toString());
        }
Ejemplo n.º 16
0
	public static string test() {
		var obj1 = new SelectManyAux(1);
		var obj2 = new SelectManyAux(2);
		var lst = new ArrayList<SelectManyAux> { obj1, obj2 };
		var sb = new StringBuilder();
		foreach (var s in lst.selectMany(p => p.getStrings())) {
			sb.append(s);
		}
		return sb.toString();
	}
Ejemplo n.º 17
0
 public WPICamera(int team)
 {
   StringBuilder stringBuilder = new StringBuilder().append("10.").append(team / 100).append(".");
   int num1 = team;
   int num2 = 100;
   int num3 = -1;
   int num4 = num2 != num3 ? num1 % num2 : 0;
   // ISSUE: explicit constructor call
   this.\u002Ector(stringBuilder.append(num4).append(".").append(11).toString());
   GC.KeepAlive((object) this);
 }
Ejemplo n.º 18
0
            public String toString()
            {
                StringBuilder outputString = new StringBuilder();

                outputString.append("Country Code: ").append(countryCode_);
                outputString.append(" National Number: ").append(nationalNumber_);
                if (hasItalianLeadingZero() && isItalianLeadingZero())
                {
                    outputString.append(" Leading Zero: true");
                }
                if (hasExtension())
                {
                    outputString.append(" Extension: ").append(extension_);
                }
                if (hasCountryCodeSource())
                {
                    outputString.append(" Country Code Source: ").append(Enum.GetName(typeof(CountryCodeSource), countryCodeSource_));
                }
                if (hasPreferredDomesticCarrierCode())
                {
                    outputString.append(" Preferred Domestic Carrier Code: ").
                    append(preferredDomesticCarrierCode_);
                }
                return(outputString.toString());
            }
Ejemplo n.º 19
0
        public void HeavyCall()
        {
            var      sb    = new StringBuilder();
            DateTime start = DateTime.Now;

            for (int i = 0; i < 1000000; i++)
            {
                sb.append('a');
            }
            DateTime end = DateTime.Now;

            Console.WriteLine(end - start);
        }
	public static string test() {
		var list = new ArrayList<string>();
		list.add("a");
		list.add("b");
		list.add("c");
		
		var sb = new StringBuilder();
		foreach (var s in list) {
			sb.append(s);
		}
		
		return sb.toString();
	}
Ejemplo n.º 21
0
        // Accrues digits and the plus sign to accruedInputWithoutFormatting for later use. If nextChar
        // contains a digit in non-ASCII format (e.g. the full-width version of digits), it is first
        // normalized to the ASCII version. The return value is nextChar itself, or its normalized
        // version, if nextChar is a digit in non-ASCII format. This method assumes its input is either a
        // digit or the plus sign.
        private char normalizeAndAccrueDigitsAndPlusSign(char nextChar, boolean rememberPosition)
        {
            char normalizedChar;

            if (nextChar == PhoneNumberUtil.PLUS_SIGN)
            {
                normalizedChar = nextChar;
                accruedInputWithoutFormatting.append(nextChar);
            }
            else
            {
                int radix = 10;
                normalizedChar = Character.forDigit(Character.digit(nextChar, radix), radix);
                accruedInputWithoutFormatting.append(normalizedChar);
                nationalNumber.append(normalizedChar);
            }
            if (rememberPosition)
            {
                positionToRemember = accruedInputWithoutFormatting.length();
            }
            return(normalizedChar);
        }
Ejemplo n.º 22
0
        /**
         * Extracts IDD and plus sign to prefixBeforeNationalNumber when they are available, and places
         * the remaining input into nationalNumber.
         *
         * @return  true when accruedInputWithoutFormatting begins with the plus sign or valid IDD for
         *     defaultCountry.
         */
        private boolean attemptToExtractIdd()
        {
            Pattern internationalPrefix =
                regexCache.getPatternForRegex("\\" + PhoneNumberUtil.PLUS_SIGN + "|" +
                                              currentMetadata.getInternationalPrefix());
            Matcher iddMatcher = internationalPrefix.matcher(accruedInputWithoutFormatting);

            if (iddMatcher.lookingAt())
            {
                isCompleteNumber = true;
                int startOfCountryCallingCode = iddMatcher.end();
                nationalNumber.setLength(0);
                nationalNumber.append(accruedInputWithoutFormatting.substring(startOfCountryCallingCode));
                prefixBeforeNationalNumber.setLength(0);
                prefixBeforeNationalNumber.append(
                    accruedInputWithoutFormatting.substring(0, startOfCountryCallingCode));
                if (accruedInputWithoutFormatting.charAt(0) != PhoneNumberUtil.PLUS_SIGN)
                {
                    prefixBeforeNationalNumber.append(SEPARATOR_BEFORE_NATIONAL_NUMBER);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 23
0
        public String toString()
        {
            StringBuilder sb = new StringBuilder();

            sb.append("java.util.regex.Matcher");
            sb.append("[pattern=" + pattern());
            sb.append(" region=");
            sb.append(regionStart() + "," + regionEnd());
            sb.append(" lastmatch=");
            if ((first >= 0) && (group() != null))
            {
                sb.append(group());
            }
            sb.append("]");
            return(sb.toString());
        }
 public virtual string getMessage()
 {
   StringBuilder stringBuilder = new StringBuilder();
   if (this.fMessage != null)
     stringBuilder.append(this.fMessage);
   stringBuilder.append("arrays first differed at element ");
   Iterator iterator = this.fIndices.iterator();
   while (iterator.hasNext())
   {
     int num = ((Integer) iterator.next()).intValue();
     stringBuilder.append("[");
     stringBuilder.append(num);
     stringBuilder.append("]");
   }
   stringBuilder.append("; ");
   stringBuilder.append(Throwable.instancehelper_getMessage((Exception) this.fCause));
   return stringBuilder.toString();
 }
Ejemplo n.º 25
0
 protected internal virtual void printFailures(Result result)
 {
   List failures = result.getFailures();
   if (failures.size() == 0)
     return;
   if (failures.size() == 1)
     this.getWriter().println(new StringBuilder().append("There was ").append(failures.size()).append(" failure:").toString());
   else
     this.getWriter().println(new StringBuilder().append("There were ").append(failures.size()).append(" failures:").toString());
   int num1 = 1;
   Iterator iterator = failures.iterator();
   while (iterator.hasNext())
   {
     Failure each = (Failure) iterator.next();
     StringBuilder stringBuilder = new StringBuilder().append("");
     int num2 = num1;
     ++num1;
     string prefix = stringBuilder.append(num2).toString();
     this.printFailure(each, prefix);
   }
 }
Ejemplo n.º 26
0
        public Matcher appendReplacement(StringBuffer sb, String replacement)
        {
            // If no match, return error
            if (first < 0)
            {
                throw new InvalidOperationException("No match available");
            }
            // Process substitution string to replace group references with groups
            int           cursor = 0;
            StringBuilder result = new StringBuilder();

            while (cursor < replacement.length())
            {
                char nextChar = replacement.charAt(cursor);
                if (nextChar == '\\')
                {
                    cursor++;
                    nextChar = replacement.charAt(cursor);
                    result.append(nextChar);
                    cursor++;
                }
                else if (nextChar == '$')
                {
                    // Skip past $
                    cursor++;
                    // A StringIndexOutOfBoundsException is thrown if
                    // this "$" is the last character in replacement
                    // string in current implementation, a IAE might be
                    // more appropriate.
                    nextChar = replacement.charAt(cursor);
                    int refNum = -1;
                    if (nextChar == '{')
                    {
                        cursor++;
                        StringBuilder gsb = new StringBuilder();
                        while (cursor < replacement.length())
                        {
                            nextChar = replacement.charAt(cursor);
                            if (ASCII.isLower(nextChar) ||
                                ASCII.isUpper(nextChar) ||
                                ASCII.isDigit(nextChar))
                            {
                                gsb.append(nextChar);
                                cursor++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (gsb.length() == 0)
                        {
                            throw new IllegalArgumentException(
                                      "named capturing group has 0 length name");
                        }
                        if (nextChar != '}')
                        {
                            throw new IllegalArgumentException(
                                      "named capturing group is missing trailing '}'");
                        }
                        String gname = gsb.toString();
                        if (ASCII.isDigit(gname.charAt(0)))
                        {
                            throw new IllegalArgumentException(
                                      "capturing group name {" + gname +
                                      "} starts with digit character");
                        }
                        if (!parentPattern.namedGroups().containsKey(gname))
                        {
                            throw new IllegalArgumentException(
                                      "No group with name {" + gname + "}");
                        }
                        refNum = parentPattern.namedGroups().get(gname);
                        cursor++;
                    }
                    else
                    {
                        // The first number is always a group
                        refNum = (int)nextChar - '0';
                        if ((refNum < 0) || (refNum > 9))
                        {
                            throw new IllegalArgumentException(
                                      "Illegal group reference");
                        }
                        cursor++;
                        // Capture the largest legal group string
                        boolean done = false;
                        while (!done)
                        {
                            if (cursor >= replacement.length())
                            {
                                break;
                            }
                            int nextDigit = replacement.charAt(cursor) - '0';
                            if ((nextDigit < 0) || (nextDigit > 9)) // not a number
                            {
                                break;
                            }
                            int newRefNum = (refNum * 10) + nextDigit;
                            if (groupCount() < newRefNum)
                            {
                                done = true;
                            }
                            else
                            {
                                refNum = newRefNum;
                                cursor++;
                            }
                        }
                    }
                    // Append group
                    if (start(refNum) != -1 && end(refNum) != -1)
                    {
                        result.append(text, start(refNum), end(refNum));
                    }
                }
                else
                {
                    result.append(nextChar);
                    cursor++;
                }
            }
            // Append the intervening text
            sb.append(text, lastAppendPosition, first);
            // Append the match substitution
            sb.append(result);
            lastAppendPosition = last;
            return(this);
        }
Ejemplo n.º 27
0
 public static void setTeam(int i)
 {
   lock ((object) ClassLiteral<NetworkTable>.Value)
   {
     StringBuilder temp_9 = new StringBuilder().append("10.").append(i / 100).append(".");
     int temp_10 = i;
     int temp_11 = 100;
     int temp_12 = -1;
     int temp_13 = temp_11 != temp_12 ? temp_10 % temp_11 : 0;
     NetworkTable.setIPAddress(temp_9.append(temp_13).append(".2").toString());
   }
 }
Ejemplo n.º 28
0
        public void HeavyCall()
        {
            var sb = new StringBuilder();
            DateTime start = DateTime.Now;
            for (int i = 0; i < 1000000; i++)
            {
                sb.append('a');
            }
            DateTime end = DateTime.Now;

            Console.WriteLine(end - start);
        }
        public static String unescapeString(char[] text, int offset, int length) {
            var sb = new StringBuilder();
            var end = offset + length;
            for (var i = offset; i < end; i++) {
                var c = text[i];
                if (c == '\\') {
                    switch (c = text[++i]) {
                    case '"':
                    case '\\':
                    case '\'':
                        sb.append(c);
                        break;
                    case '0':
                        sb.append((char)0);
                        break;
                    case 'a':
                        sb.append((char)7);
                        break;
                    case 'b':
                        sb.append((char)8);
                        break;
                    case 'f':
                        sb.append((char)12);
                        break;
                    case 'n':
                        sb.append((char)10);
                        break;
                    case 'r':
                        sb.append((char)13);
                        break;
                    case 't':
                        sb.append((char)9);
                        break;
                    case 'v':
                        sb.append((char)11);
                        break;

                    case 'u': {
                        var value = 0;
                        for (var j = 0; j < 4; j++) {
                            value = value * 16 + ParserHelper.scanHexDigit(text[++i]);
                        }
                        sb.append((char)value);
                        break;
                    }
                    case 'U': {
                        var value = 0;
                        for (var j = 0; j < 4; j++) {
                            value = value * 16 + ParserHelper.scanHexDigit(text[++i]);
                        }
                        sb.append((char)value);
                        value = 0;
                        for (int j = 0; j < 4; j++) {
                            value = value * 16 + ParserHelper.scanHexDigit(text[++i]);
                        }
                        sb.append((char)value);
                        break;
                    }
                    case 'x': {
                        var value = ParserHelper.scanHexDigit(text[++i]);
                        var d = ParserHelper.scanHexDigit(text[i + 1]);
                        if (d > -1) {
                            value = value * 16 + d;
                            if ((d = ParserHelper.scanHexDigit(text[++i + 1])) > -1) {
                                value = value * 16 + d;
                                if ((d = ParserHelper.scanHexDigit(text[++i + 1])) > -1) {
                                    value = value * 16 + d;
                                    i++;
                                }
                            }
                        }
                        sb.append((char)value);
                        break;
                    }
                    }
                } else {
                    sb.append(c);
                }
            }
            return sb.toString();
        }
	public static string test() {
		var sb = new StringBuilder();
		sb.append("ABC");
		sb.setLength(2);
		return sb.toString();
	}
Ejemplo n.º 31
0
        private String inputDigitWithOptionToRememberPosition(char nextChar, boolean rememberPosition)
        {
            accruedInput.append(nextChar);
            if (rememberPosition)
            {
                originalPosition = accruedInput.length();
            }
            // We do formatting on-the-fly only when each character entered is either a digit, or a plus
            // sign (accepted at the start of the number only).
            if (!isDigitOrLeadingPlusSign(nextChar))
            {
                ableToFormat       = false;
                inputHasFormatting = true;
            }
            else
            {
                nextChar = normalizeAndAccrueDigitsAndPlusSign(nextChar, rememberPosition);
            }
            if (!ableToFormat)
            {
                // When we are unable to format because of reasons other than that formatting chars have been
                // entered, it can be due to really long IDDs or NDDs. If that is the case, we might be able
                // to do formatting again after extracting them.
                if (inputHasFormatting)
                {
                    return(accruedInput.toString());
                }
                else if (attemptToExtractIdd())
                {
                    if (attemptToExtractCountryCallingCode())
                    {
                        return(attemptToChoosePatternWithPrefixExtracted());
                    }
                }
                else if (ableToExtractLongerNdd())
                {
                    // Add an additional space to separate long NDD and national significant number for
                    // readability. We don't set shouldAddSpaceAfterNationalPrefix to true, since we don't want
                    // this to change later when we choose formatting templates.
                    prefixBeforeNationalNumber.append(SEPARATOR_BEFORE_NATIONAL_NUMBER);
                    return(attemptToChoosePatternWithPrefixExtracted());
                }
                return(accruedInput.toString());
            }

            // We start to attempt to format only when at least MIN_LEADING_DIGITS_LENGTH digits (the plus
            // sign is counted as a digit as well for this purpose) have been entered.
            switch (accruedInputWithoutFormatting.length())
            {
            case 0:
            case 1:
            case 2:
                return(accruedInput.toString());

            default:
                if (accruedInputWithoutFormatting.length() == 3)
                {
                    if (attemptToExtractIdd())
                    {
                        isExpectingCountryCallingCode = true;
                    }
                    else // No IDD or plus sign is found, might be entering in national format.
                    {
                        nationalPrefixExtracted = removeNationalPrefixFromNationalNumber();
                        return(attemptToChooseFormattingPattern());
                    }
                }
                if (isExpectingCountryCallingCode)
                {
                    if (attemptToExtractCountryCallingCode())
                    {
                        isExpectingCountryCallingCode = false;
                    }
                    return(prefixBeforeNationalNumber + nationalNumber.toString());
                }
                if (possibleFormats.size() > 0) // The formatting pattern is already chosen.
                {
                    String tempNationalNumber = inputDigitHelper(nextChar);
                    // See if the accrued digits can be formatted properly already. If not, use the results
                    // from inputDigitHelper, which does formatting based on the formatting pattern chosen.
                    String formattedNumber = attemptToFormatAccruedDigits();
                    if (formattedNumber.length() > 0)
                    {
                        return(formattedNumber);
                    }
                    narrowDownPossibleFormats(nationalNumber.toString());
                    if (maybeCreateNewTemplate())
                    {
                        return(inputAccruedNationalNumber());
                    }
                    return(ableToFormat
             ? appendNationalNumber(tempNationalNumber)
             : accruedInput.toString());
                }
                else
                {
                    return(attemptToChooseFormattingPattern());
                }
            }
        }
		public void save(IFile file) {
			try {
				var document = XmlHelper.load(new StringReader(EMPTY_DOC));
				var libs = (Element)document.getElementsByTagName("libraries").item(0);
				foreach (var lib in this.Libraries) {
					var e = document.createElement("library");
					libs.appendChild(e);
					e.setAttribute("name", lib.Path);
					if (!lib.Enabled) {
						e.setAttribute("enabled", "false");
					}
				}
				if (this.PreprocessorSymbols.any()) {
					var sb = new StringBuilder();
					var first = true;
					foreach (String s in this.PreprocessorSymbols) {
						if (first) {
							first = false;
						} else {
							sb.append(';');
						}
						sb.append(s);
					}
					var e = document.createElement("preprocessorSymbols");
					document.getDocumentElement().appendChild(e);
					e.setTextContent(sb.toString());
				}
				var outputElt = document.createElement("outputPath");
				document.getDocumentElement().appendChild(outputElt);
				outputElt.setTextContent(this.OutputPath);
				
	            var writer = new StringWriter();
				XmlHelper.save(document, writer);
	            var bytes = writer.toString().getBytes("UTF-8");
	            var stream = new ByteArrayInputStream(bytes);
	            if (file.exists()) {
	            	file.setContents(stream, IResource.FORCE, null);
	            } else {
	            	file.create(stream, true, null);
	            }
			} catch (Exception e) {
				Environment.logException(e);
			}
		}
 private long readUTFSpan(StringBuilder sbuf, long utflen)
 {
     int cpos = 0;
     int start = pos;
     int avail = Math.min(end - pos, CHAR_BUF_SIZE);
     // stop short of last char unless all of utf bytes @in buffer
     int stop = pos + ((utflen > avail) ? avail - 2 : (int) utflen);
     boolean outOfBounds = false;
     try {
     while (pos < stop) {
         int b1, b2, b3;
         b1 = buf[pos++] & 0xFF;
         switch (b1 >> 4) {
             case 0:
             case 1:
             case 2:
             case 3:
             case 4:
             case 5:
             case 6:
             case 7:   // 1 byte format: 0xxxxxxx
                 cbuf[cpos++] = (char) b1;
                 break;
             case 12:
             case 13:  // 2 byte format: 110xxxxx 10xxxxxx
                 b2 = buf[pos++];
                 if ((b2 & 0xC0) != 0x80) {
                     throw new Exception();
                 }
                 cbuf[cpos++] = (char) (((b1 & 0x1F) << 6) |
                                        ((b2 & 0x3F) << 0));
                 break;
             case 14:  // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
                 b3 = buf[pos + 1];
                 b2 = buf[pos + 0];
                 pos += 2;
                 if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
                     throw new Exception();
                 }
                 cbuf[cpos++] = (char) (((b1 & 0x0F) << 12) |
                                        ((b2 & 0x3F) << 6) |
                                        ((b3 & 0x3F) << 0));
                 break;
             default:  // 10xx xxxx, 1111 xxxx
                 throw new Exception();
         }
     }
     } catch (Exception) {
     outOfBounds = true;
     } finally {
     if (outOfBounds || (pos - start) > utflen) {
         /*
          * Fix for 4450867: if a malformed utf char causes the
          * conversion loop to scan past the expected end of the utf
          * string, only consume the expected number of utf bytes.
          */
         pos = start + (int) utflen;
         throw new Exception();
     }
     }
     sbuf.append(cbuf, 0, cpos);
     return pos - start;
 }
Ejemplo n.º 34
0
 private String getTypeName(String packageName, int offset, int length) {
     var sb = new StringBuilder();
     if (!Helper.isNullOrEmpty(packageName)) {
         sb.append(packageName).append('/');
     }
     context.appendIdentifier(sb, offset, length);
     return sb.toString();
 }
 private static String getIdName(TypeInfo type) {
     switch (type.TypeKind) {
     case Boolean:
         return "boolean";
     case Byte:
         return "byte";
     case Char:
         return "char";
     case Double:
         return "double";
     case Float:
         return "float";
     case Int:
         return "int";
     case Long:
         return "long";
     case Short:
         return "short";
     case Void:
         return "void";
     case Array:
         return getIdName(type.ElementType) + "[]";
     default:
         var result = type.FullName.replace('/', '.').replace('$', '.');
         if (type.OriginalTypeDefinition != type && type.GenericArguments.any()) {
             var sb = new StringBuilder();
             sb.append(result).append('{');
             var first = true;
             foreach (var t in type.GenericArguments) {
                 if (first) {
                     first = false;
                 } else {
                     sb.append(", ");
                 }
                 sb.append(getIdName(t));
             }
             sb.append('}');
             result = sb.toString();
         }
         return result;
     }
 }
 private static String getIdString(MethodInfo method) {
     var p = method.getUserData(typeof(PropertyMemberInfo));
     var sb = new StringBuilder();
     if (p != null) {
         sb.append("P:");
         sb.append(getIdName(method.DeclaringType)).append('.');
         sb.append(p.Name);
         return sb.toString();
     }
     var i = method.getUserData(typeof(IndexerMemberInfo));
     int nparams = method.Parameters.count();
     if (i != null) {
         sb.append("P:");
         if (method.ReturnType == method.ReturnType.Library.VoidType) {
             nparams--;
         }
     } else {
         sb.append("M:");
     }
     sb.append(getIdName(method.DeclaringType)).append('.');
     sb.append((method.Name.equals("<init>")) ? "#init" : method.Name);
     if (method.Parameters.any()) {
         sb.append('(');
         var first = true;
         foreach (var t in method.Parameters.take(nparams).select(p => p.Type)) {
             if (first) {
                 first = false;
             } else {
                 sb.append(",");
             }
             sb.append(getIdName(t));
         }
         sb.append(')');
     }
     return sb.toString();
 }
 private int readUTFChar(StringBuilder sbuf, long utflen)
 {
     int b1, b2, b3;
     b1 = readByte() & 0xFF;
     switch (b1 >> 4) {
     case 0:
     case 1:
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
     case 7:     // 1 byte format: 0xxxxxxx
         sbuf.append((char) b1);
         return 1;
     case 12:
     case 13:    // 2 byte format: 110xxxxx 10xxxxxx
         if (utflen < 2) {
             throw new Exception();
         }
         b2 = readByte();
         if ((b2 & 0xC0) != 0x80) {
             throw new Exception();
         }
         sbuf.append((char) (((b1 & 0x1F) << 6) |
                             ((b2 & 0x3F) << 0)));
         return 2;
     case 14:    // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
         if (utflen < 3) {
             if (utflen == 2) {
                 readByte();         // consume remaining byte
             }
             throw new Exception();
         }
         b2 = readByte();
         b3 = readByte();
         if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
             throw new Exception();
         }
         sbuf.append((char) (((b1 & 0x0F) << 12) |
                             ((b2 & 0x3F) << 6) |
                             ((b3 & 0x3F) << 0)));
         return 3;
     default:   // 10xx xxxx, 1111 xxxx
         throw new Exception();
     }
 }
 public static void unescapeIdentifier(StringBuilder sb, char[] text, int offset, int length) {
     var end = offset + length;
     if (text[offset] == '@') {
         offset++;
     }
     for (var i = offset; i < end; i++) {
         var c = text[i];
         if (c == '\\') {
             c = text[++i];
             if (c == 'u') {
                 var value = 0;
                 for (var j = 0; j < 4; j++) {
                     value = value * 16 + ParserHelper.scanHexDigit(text[++i]);
                 }
                 sb.append((char)value);
             } else {
                 var value = 0;
                 for (var j = 0; j < 4; j++) {
                     value = value * 16 + ParserHelper.scanHexDigit(text[++i]);
                 }
                 sb.append((char)value);
                 value = 0;
                 for (int j = 0; j < 4; j++) {
                     value = value * 16 + ParserHelper.scanHexDigit(text[++i]);
                 }
                 sb.append((char)value);
             }
         } else {
             sb.append(c);
         }
     }
 }
 public static String unescapeVerbatimString(char[] text, int offset, int length) {
     var sb = new StringBuilder();
     var end = offset + length;
     for (var i = offset; i < end; i++) {
         var c = text[i];
         if (c == '"') {
             i++;
         }
         sb.append(c);
     }
     return sb.toString();
 }
 public static String decodeDocumentation(char[] text, int offset, int length) {
     var end = offset + length;
     offset++;
     var sb = new StringBuilder();
     if (text[offset] == '*') {
         offset += 2;
         for (var i = offset; i < end; i++) {
             var c = text[i];
             switch (c) {
             case '\r':
                 sb.append(c);
                 if (text[i + 1] == '\n') {
                     i++;
                 }
                 goto case '\n';
                 
             case '\u2028':
             case '\u2029':
             case '\n':
                 sb.append(c);
                 var done = false;
                 while (i + 1 < end && !done) {
                     switch (text[i + 1]) {
                     case ' ':
                     case '\t':
                     case '\v':
                     case '\f':
                         i++;
                         break;
                     case '*':
                         if (text[i + 2] != '/') {
                             i++;
                             if (text[i + 1] == ' ') {
                                 i++;
                             }
                         }
                         goto default;
                     default:
                         done = true;
                         break;
                     }
                 }
                 break;
                
             case '*':
                 if (text[i + 1] != '/') {
                     sb.append(c);
                 } else {
                     i++;
                 }
                 break;
                
             default:
                 sb.append(c);
                 break;
             }
         }                
     } else {
         offset += 2;
         if (offset < end && text[offset] == ' ') {
             offset++;
         }
         for (var i = offset; i < end; i++) {
             var c = text[i];
             switch (c) {
             case '\r':
                 sb.append(c);
                 if (text[i + 1] == '\n') {
                     c = '\n';
                     i++;
                 }
                 goto case '\n';
                 
             case '\u2028':
             case '\u2029':
             case '\n':
                 sb.append(c);
                 do {
                     i++;
                 } while (i < end && text[i] != '/');
                 i += 2;
                 if (i + 1 < end && text[i + 1] == ' ') {
                     i++;
                 }
                 break;
                 
             default:
                 sb.append(c);
                 break;
             }
         }
     }
     return sb.toString();
 }
Ejemplo n.º 41
0
 public String toString()
 {
     StringBuilder sb = new StringBuilder();
     sb.append("java.util.regex.Matcher");
     sb.append("[pattern=" + pattern());
     sb.append(" region=");
     sb.append(regionStart() + "," + regionEnd());
     sb.append(" lastmatch=");
     if ((first >= 0) && (group() != null)) {
     sb.append(group());
     }
     sb.append("]");
     return sb.toString();
 }
Ejemplo n.º 42
0
        public CompilerResults compileFromFiles(CompilerParameters parameters, File[] files) {
            var results = new CompilerResults();
            this.context = new CompilerContext(parameters, results);
            this.statementValidator = new StatementValidator(this.context);
            this.expressionValidator = new ExpressionValidator(this.context);
            this.statementValidator.ExpressionValidator = this.expressionValidator;
            this.expressionValidator.StatementValidator = this.statementValidator;
            this.reachabilityChecker = new ReachabilityChecker(context);
            this.assignmentChecker = new AssignmentChecker(context);
            this.bytecodeGenerator = new BytecodeGenerator(context);
            bool tragicError = false;
			
            var buffer = new char[4096];
            var sb = new StringBuilder();
            var parser = new Parser();
            
            foreach (var file in files) {
                sb.setLength(0);
                InputStreamReader reader = null;
                try {
                    reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
                    int read;
                    while ((read = reader.read(buffer)) != -1) {
                        sb.append(buffer, 0, read);
                    }
                    
                    var text = new char[sb.length()];
                    sb.getChars(0, sizeof(text), text, 0);
                    if (sizeof(text) > 0) {
                        if (text[sizeof(text) - 1] == '\u001a') {
                            text[sizeof(text) - 1] = ' ';
                        }
                    }
                    var preprocessor = new Preprocessor(results.codeErrorManager, text);
                    preprocessor.Filename = file.getAbsolutePath();
					preprocessor.Symbols.addAll(parameters.Symbols);
                    
                    var scanner = new PreprocessedTextScanner(results.codeErrorManager, preprocessor.preprocess());
                    scanner.Filename = file.getAbsolutePath();
                    var compilationUnit = parser.parseCompilationUnit(scanner);
                    
                    if (compilationUnit != null) {
                        compilationUnit.Symbols = preprocessor.Symbols;
                        context.CompilationUnits.add(compilationUnit);
                    }
                } catch (CodeErrorException) {
				} catch (Exception e) {
					e.printStackTrace();
					tragicError = true;
					break;
                } finally {
                    if (reader != null) {
                        try {
                            reader.close();
                        } catch (IOException) {
                        }
                    }
                }
            }
            if (!tragicError) {
				if (!context.HasErrors) {
					if (parameters.ProgressTracker != null) {
						parameters.ProgressTracker.compilationStageFinished(CompilationStage.Parsing);
					}
					doCompile();
				}
			}
            this.context = null;
            this.statementValidator = null;
            this.expressionValidator = null;
            this.reachabilityChecker = null;
            this.assignmentChecker = null;
            this.queryTranslator = null;
            this.documentationBuilder = null;
			
			if (parameters.ProgressTracker != null) {
				parameters.ProgressTracker.compilationFinished();
			}
            return results;
        }
Ejemplo n.º 43
0
 public Matcher appendReplacement(StringBuffer sb, String replacement)
 {
     // If no match, return error
     if (first < 0)
     throw new InvalidOperationException("No match available");
     // Process substitution string to replace group references with groups
     int cursor = 0;
     StringBuilder result = new StringBuilder();
     while (cursor < replacement.length()) {
     char nextChar = replacement.charAt(cursor);
     if (nextChar == '\\') {
         cursor++;
         nextChar = replacement.charAt(cursor);
         result.append(nextChar);
         cursor++;
     } else if (nextChar == '$') {
         // Skip past $
         cursor++;
         // A StringIndexOutOfBoundsException is thrown if
         // this "$" is the last character in replacement
         // string in current implementation, a IAE might be
         // more appropriate.
         nextChar = replacement.charAt(cursor);
         int refNum = -1;
         if (nextChar == '{') {
             cursor++;
             StringBuilder gsb = new StringBuilder();
             while (cursor < replacement.length()) {
                 nextChar = replacement.charAt(cursor);
                 if (ASCII.isLower(nextChar) ||
                     ASCII.isUpper(nextChar) ||
                     ASCII.isDigit(nextChar)) {
                     gsb.append(nextChar);
                     cursor++;
                 } else {
                     break;
                 }
             }
             if (gsb.length() == 0)
                 throw new IllegalArgumentException(
                     "named capturing group has 0 length name");
             if (nextChar != '}')
                 throw new IllegalArgumentException(
                     "named capturing group is missing trailing '}'");
             String gname = gsb.toString();
             if (ASCII.isDigit(gname.charAt(0)))
                 throw new IllegalArgumentException(
                     "capturing group name {" + gname +
                     "} starts with digit character");
             if (!parentPattern.namedGroups().containsKey(gname))
                 throw new IllegalArgumentException(
                     "No group with name {" + gname + "}");
             refNum = parentPattern.namedGroups().get(gname);
             cursor++;
         } else {
             // The first number is always a group
             refNum = (int)nextChar - '0';
             if ((refNum < 0)||(refNum > 9))
                 throw new IllegalArgumentException(
                     "Illegal group reference");
             cursor++;
             // Capture the largest legal group string
             boolean done = false;
             while (!done) {
                 if (cursor >= replacement.length()) {
                     break;
                 }
                 int nextDigit = replacement.charAt(cursor) - '0';
                 if ((nextDigit < 0)||(nextDigit > 9)) { // not a number
                     break;
                 }
                 int newRefNum = (refNum * 10) + nextDigit;
                 if (groupCount() < newRefNum) {
                     done = true;
                 } else {
                     refNum = newRefNum;
                     cursor++;
                 }
             }
         }
         // Append group
         if (start(refNum) != -1 && end(refNum) != -1)
             result.append(text, start(refNum), end(refNum));
     } else {
         result.append(nextChar);
         cursor++;
     }
     }
     // Append the intervening text
     sb.append(text, lastAppendPosition, first);
     // Append the match substitution
     sb.append(result);
     lastAppendPosition = last;
     return this;
 }
Ejemplo n.º 44
0
 private String getPackageName(String outerPackage, PackageDeclarationNode packageDeclaration, char separator) {
     var sb = new StringBuilder();
     var first = true;
     if (!Helper.isNullOrEmpty(outerPackage)) {
         sb.append(outerPackage);
         first = false;
     }
     foreach (var identifier in packageDeclaration.Identifiers) {
         if (first) {
             first = false;
         } else {
             sb.append(separator);
         }
         var id = context.getIdentifier(identifier.Offset, identifier.Length);
         sb.append(id);
         identifier.addUserData(id);
     }
     return sb.toString();
 }