MCPcopy Create free account
hub / github.com/diyhi/bbs / saveConvert

Method saveConvert

src/main/java/cms/utils/CommentedProperties.java:614–670  ·  view source on GitHub ↗
(String theString,
			boolean escapeSpace,
			boolean escapeUnicode)

Source from the content-addressed store, hash-verified

612 * special characters with a preceding slash
613 */
614 private String saveConvert(String theString,
615 boolean escapeSpace,
616 boolean escapeUnicode) {
617 int len = theString.length();
618 int bufLen = len * 2;
619 if (bufLen < 0) {
620 bufLen = Integer.MAX_VALUE;
621 }
622 StringBuffer outBuffer = new StringBuffer(bufLen);
623
624 for(int x=0; x<len; x++) {
625 char aChar = theString.charAt(x);
626 // Handle common case first, selecting largest block that
627 // avoids the specials below
628 if ((aChar > 61) && (aChar < 127)) {
629 if (aChar == '\\') {
630 outBuffer.append('\\'); outBuffer.append('\\');
631 continue;
632 }
633 outBuffer.append(aChar);
634 continue;
635 }
636 switch(aChar) {
637 case ' ':
638 if (x == 0 || escapeSpace)
639 outBuffer.append('\\');
640 outBuffer.append(' ');
641 break;
642 case '\t':outBuffer.append('\\'); outBuffer.append('t');
643 break;
644 case '\n':outBuffer.append('\\'); outBuffer.append('n');
645 break;
646 case '\r':outBuffer.append('\\'); outBuffer.append('r');
647 break;
648 case '\f':outBuffer.append('\\'); outBuffer.append('f');
649 break;
650 case '=': // Fall through
651 case ':': // Fall through
652 case '#': // Fall through
653 case '!':
654 outBuffer.append('\\'); outBuffer.append(aChar);
655 break;
656 default:
657 if (((aChar < 0x0020) || (aChar > 0x007e)) & escapeUnicode ) {
658 outBuffer.append('\\');
659 outBuffer.append('u');
660 outBuffer.append(toHex((aChar >> 12) & 0xF));
661 outBuffer.append(toHex((aChar >> 8) & 0xF));
662 outBuffer.append(toHex((aChar >> 4) & 0xF));
663 outBuffer.append(toHex( aChar & 0xF));
664 } else {
665 outBuffer.append(aChar);
666 }
667 }
668 }
669 return outBuffer.toString();
670 }
671

Callers 1

store0Method · 0.95

Calls 2

toHexMethod · 0.95
toStringMethod · 0.45

Tested by

no test coverage detected