MCPcopy Index your code
hub / github.com/antlr/codebuff / toString

Method toString

output/java8/1.4.14/StringRenderer.java:47–68  ·  view source on GitHub ↗
(Object o, String formatString, Locale locale)

Source from the content-addressed store, hash-verified

45public class StringRenderer implements AttributeRenderer {
46 // trim(s) and strlen(s) built-in funcs; these are format options
47 @Override
48 public String toString(Object o, String formatString, Locale locale) {
49 String s = (String)o;
50 if ( formatString==null ) return s;
51 if ( formatString.equals("upper") ) return s.toUpperCase(locale);
52 if ( formatString.equals("lower") ) return s.toLowerCase(locale);
53 if ( formatString.equals("cap") ) {
54 return (s.length()>0) ? Character.toUpperCase(s.charAt(0)) +s.substring(1) : s;
55 }
56 if ( formatString.equals("url-encode") ) {
57 try {
58 return URLEncoder.encode(s, "UTF-8");
59 }
60 catch (UnsupportedEncodingException ex) {
61 // UTF-8 is standard, should always be available
62 }
63 }
64 if ( formatString.equals("xml-encode") ) {
65 return escapeHTML(s);
66 }
67 return String.format(locale, formatString, s);
68 }
69
70 public static String escapeHTML(String s) {
71 if ( s==null ) {

Callers

nothing calls this directly

Calls 7

escapeHTMLMethod · 0.95
equalsMethod · 0.65
toUpperCaseMethod · 0.45
toLowerCaseMethod · 0.45
lengthMethod · 0.45
encodeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected