Java Java String Format toJavaString(final String s)

Here you can find the source of toJavaString(final String s)

Description

to Java String

License

Open Source License

Declaration

static public String toJavaString(final String s) 

Method Source Code

//package com.java2s;
/*********************************************************************************************
 *
 *
 * 'StringUtils.java', in plugin 'msi.gama.core', is part of the source code of the
 * GAMA modeling and simulation platform.
 * (c) 2007-2014 UMI 209 UMMISCO IRD/UPMC & Partners
 *
 * Visit https://code.google.com/p/gama-platform/ for license information and developers contact.
 *
 *
 **********************************************************************************************/

public class Main {
    static public String toJavaString(final String s) {
        if (s == null) {
            return null;
        }//  ww w. j a v a 2  s  .  co m
        String t = s.trim();
        if (!isGamaString(t)) {
            return s;
        }
        if (t.length() >= 2) {
            return t.substring(1, t.length() - 1);
        }
        return s;
    }

    static public boolean isGamaString(final String s) {
        if (s == null) {
            return false;
        }
        int n = s.length();
        if (n == 0 || n == 1) {
            return false;
        }
        if (s.charAt(0) != '\'') {
            return false;
        }
        if (s.charAt(n - 1) != '\'') {
            return false;
        }
        return true;
    }
}

Related

  1. toJavaScriptEncode(String string)
  2. toJavaScriptSafeString(String content)
  3. toJavaSecs(long secs)
  4. toJavaSourceType(String type)
  5. toJavaStaticIdentifier(String string)
  6. toJavaString(String buf)
  7. toJavaString(String text)
  8. toJavaTime(double time)
  9. toJavaTypeIdentifier(String string)