Java String Quote quote(String s)

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

Description

quote

License

Open Source License

Declaration

private static String quote(String s) 

Method Source Code

//package com.java2s;

public class Main {
    private static String quote(String s) {
        int slashEIndex = s.indexOf("\\E");
        if (slashEIndex == -1)
            return "\\Q" + s + "\\E";

        StringBuffer sb = new StringBuffer(s.length() * 2);
        sb.append("\\Q");
        slashEIndex = 0;/*from ww  w  .ja va2s .  c  o  m*/
        int current = 0;
        while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
            sb.append(s.substring(current, slashEIndex));
            current = slashEIndex + 2;
            sb.append("\\E\\\\E\\Q");
        }
        sb.append(s.substring(current, s.length()));
        sb.append("\\E");
        return sb.toString();
    }
}

Related

  1. quote(String s)
  2. quote(String s)
  3. quote(String s)
  4. quote(String s)
  5. quote(String s)
  6. quote(String s)
  7. quote(String s)
  8. quote(String s)
  9. quote(String s)