Java Integer Create toInternalString(String s)

Here you can find the source of toInternalString(String s)

Description

to Internal String

License

Open Source License

Declaration

public static String toInternalString(String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toInternalString(String s) {
        String newString;//from w  w  w .  j a  va  2  s.c  o m
        if (s.charAt(0) == '"') {
            int len = s.length();
            int bufferLen = 0;
            char[] buffer = new char[len];
            for (int i = 1; i < len - 1; ++i) {
                char c = s.charAt(i);
                if (c == '\\') {
                    //ESCA-JAVA0119 
                    ++i;
                    c = s.charAt(i);
                    if (c == 'n') {
                        c = '\n';
                    } else if (c == 'r') {
                        // simply discard '\r'
                        continue;
                    }
                }
                buffer[bufferLen] = c;
                ++bufferLen;
            }
            newString = new String(buffer, 0, bufferLen);
        } else {
            newString = s;
        }
        return newString.intern();
    }
}

Related

  1. toInternalName(String className)
  2. toInternalName(String className)
  3. toInternalName(String className)
  4. toInternalName(String className)
  5. toInternalName(String fullName)
  6. toInternalValue(final double value)
  7. toInternalVariableName(String varName)
  8. toInternLink(String title, String url)
  9. toInterval(long i)