Java String Quote quoteValues(String value)

Here you can find the source of quoteValues(String value)

Description

quote Values

License

Open Source License

Declaration

public static String quoteValues(String value) 

Method Source Code

//package com.java2s;

public class Main {
    public static String quoteValues(String value) {
        if (value.equals("true"))
            return "\"true\"^^xsd:boolean";
        if (value.equals("false"))
            return "\"false\"^^xsd:boolean";

        // Short circuit: not numeric
        if (value.startsWith("\"") || (value.length() > 0 && Character.isLetter(value.charAt(0))))
            return value;

        // Try to convert to integer
        try {//w w  w .  j  ava2  s. c  om
            Integer.parseInt(value);
            return "\"" + value + "\"^^xsd:int";
        } catch (NumberFormatException e) {
        }
        // Try to convert to double
        try {
            Double.parseDouble(value);
            return "\"" + value + "\"^^xsd:double";
        } catch (NumberFormatException e) {
        }
        return value;
    }

    public static int parseInt(String arg2) {
        if (!arg2.endsWith("^^xsd:int"))
            throw new RuntimeException("Arg2 is not a valid integer: " + arg2);
        int closingQuoteIndex = arg2.lastIndexOf('"');
        return Integer.parseInt(arg2.substring(1, closingQuoteIndex));
    }
}

Related

  1. quoteTo(CharSequence cs, StringBuilder target)
  2. quoteTokenize(String clientResponse)
  3. QuoteValue(String str)
  4. quoteValue(String value)
  5. QuoteValueIfNeeded(String str)
  6. quoteWhitespaces(String path)
  7. quoteWrap(String name)