/** * Convert a Java char to the escaped form that must be used in .properties files. * * @param c the Java char * @return escaped string */ public static String escape(char c) { return escape(c, true, true, true); }
/** * Convert a Java char to the escaped form that must be used in .properties files. * * @param c the Java char * @return escaped string */ public static String escape(char c) { return escape(c, true, true, true); }
public static String escape(String s, boolean escapeCommentCharsAndLeadingWhitespaces) { StringBuilder sb= new StringBuilder(s.length()); int length= s.length(); for (int i= 0; i < length; i++){ char c= s.charAt(i); sb.append(PropertiesFileEscapes.escape(c)); } if(!escapeCommentCharsAndLeadingWhitespaces) return sb.toString(); return escapeLeadingWhiteSpaces(escapeCommentChars(sb.toString())); }
/** * Convert characters in a Java string to the escaped form that must be used in .properties * files. * * @param s the Java string * @param escapeWhitespaceChars if <code>true</code>, escape whitespace characters * @param escapeBackslash if <code>true</code>, escape backslash characters * @param escapeUnicodeChars if <code>true</code>, escape unicode characters * @return escaped string */ public static String escape(String s, boolean escapeWhitespaceChars, boolean escapeBackslash, boolean escapeUnicodeChars) { StringBuilder sb= new StringBuilder(s.length()); int length= s.length(); for (int i= 0; i < length; i++) { char c= s.charAt(i); sb.append(escape(c, escapeWhitespaceChars, escapeBackslash, escapeUnicodeChars)); } return sb.toString(); }
/** * Convert characters in a Java string to the escaped form that must be used in .properties * files. * * @param s the Java string * @param escapeWhitespaceChars if <code>true</code>, escape whitespace characters * @param escapeBackslash if <code>true</code>, escape backslash characters * @param escapeUnicodeChars if <code>true</code>, escape unicode characters * @return escaped string */ public static String escape(String s, boolean escapeWhitespaceChars, boolean escapeBackslash, boolean escapeUnicodeChars) { StringBuffer sb= new StringBuffer(s.length()); int length= s.length(); for (int i= 0; i < length; i++) { char c= s.charAt(i); sb.append(escape(c, escapeWhitespaceChars, escapeBackslash, escapeUnicodeChars)); } return sb.toString(); }
public static String escape(String s, boolean escapeCommentCharsAndLeadingWhitespaces) { StringBuffer sb= new StringBuffer(s.length()); int length= s.length(); for (int i= 0; i < length; i++){ char c= s.charAt(i); sb.append(PropertiesFileEscapes.escape(c)); } if(!escapeCommentCharsAndLeadingWhitespaces) return sb.toString(); return escapeLeadingWhiteSpaces(escapeCommentChars(sb.toString())); }
private ICompletionProposal escape(DocumentCommand command) { try { String charsetName= fFile.getCharset(); if (!charsetName.equals(fCharsetName)) { fCharsetName= charsetName; fCharsetEncoder= Charset.forName(fCharsetName).newEncoder(); } } catch (CoreException e) { return null; } String text= command.text; boolean escapeUnicodeChars= !fCharsetEncoder.canEncode(text); boolean escapeBackslash= (text.length() > 1) && ((escapeUnicodeChars && PropertiesFileEscapes.containsUnescapedBackslash(text)) || PropertiesFileEscapes.containsInvalidEscapeSequence(text)); if (!escapeUnicodeChars && !escapeBackslash) return null; command.text= PropertiesFileEscapes.escape(text, false, false, escapeUnicodeChars); if (escapeBackslash) { String proposalText= PropertiesFileEscapes.escape(text, false, true, escapeUnicodeChars); return new EscapeBackslashCompletionProposal(proposalText, command.offset, command.text.length(), PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashesInOriginalString); } return null; }
private ICompletionProposal escape(DocumentCommand command) { try { String charsetName= fFile.getCharset(); if (!charsetName.equals(fCharsetName)) { fCharsetName= charsetName; fCharsetEncoder= Charset.forName(fCharsetName).newEncoder(); } } catch (CoreException e) { return null; } String text= command.text; boolean escapeUnicodeChars= !fCharsetEncoder.canEncode(text); boolean escapeBackslash= (text.length() > 1) && ((escapeUnicodeChars && PropertiesFileEscapes.containsUnescapedBackslash(text)) || PropertiesFileEscapes.containsInvalidEscapeSequence(text)); if (!escapeUnicodeChars && !escapeBackslash) return null; command.text= PropertiesFileEscapes.escape(text, false, false, escapeUnicodeChars); if (escapeBackslash) { String proposalText= PropertiesFileEscapes.escape(text, false, true, escapeUnicodeChars); return new EscapeBackslashCompletionProposal(proposalText, command.offset, command.text.length(), PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashesInOriginalString); } return null; }
if (resultingCollections == null) return true; resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.escape(text, false, true, false), proposalOffset, proposalLength, PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashes)); return true;
if (resultingCollections == null) return true; resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.escape(text, false, true, false), proposalOffset, proposalLength, PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashes)); return true;