11package restx .common ;
22
33import com .google .common .base .Optional ;
4+ import com .google .common .collect .ImmutableList ;
45import com .google .common .collect .ImmutableMap ;
56import com .google .common .io .CharSource ;
67import com .google .common .io .CharStreams ;
@@ -24,21 +25,30 @@ public class StdRestxConfig implements RestxConfig {
2425 public static RestxConfig parse (String origin , CharSource charSource ) throws IOException {
2526 List <ConfigElement > elements = new ArrayList <>();
2627 StringBuilder doc = new StringBuilder ();
27- int lineCount = 0 ;
28- for (String line : charSource .readLines ()) {
29- lineCount ++;
28+ ImmutableList <String > lines = charSource .readLines ();
29+
30+ for (int lineCount = 0 ; lineCount < lines .size (); lineCount ++) {
31+ String line = lines .get (lineCount );
3032 if (line .startsWith ("#" )) {
3133 doc .append (line .substring (1 ).trim ()).append ("\n " );
3234 } else if (!line .trim ().isEmpty ()) {
33- int index = line .indexOf ('=' );
34- if (index == -1 ) {
35+ int equalIndex = line .indexOf ('=' );
36+ if (equalIndex == -1 ) {
3537 throw new IOException ("invalid config " + origin + " at line " + lineCount + ":" +
3638 " line does not contain the equals sign '='" );
3739 }
38- String key = line .substring (0 , index ).trim ();
39- String value = line .substring (index + 1 ).trim ();
40+ String key = line .substring (0 , equalIndex ).trim ();
41+ StringBuilder value = new StringBuilder ();
42+ String lineValue = line .substring (equalIndex + 1 ).trim ();
43+ while (lineValue .endsWith ("\\ " ) && lineCount +1 < lines .size ()) {
44+ value .append (lineValue .substring (0 , lineValue .length () - "\\ " .length ()));
45+
46+ lineCount ++;
47+ lineValue = lines .get (lineCount ).trim ();
48+ }
49+ value .append (lineValue );
4050
41- elements .add (ConfigElement .of (origin , doc .toString ().trim (), key , value ));
51+ elements .add (ConfigElement .of (origin , doc .toString ().trim (), key , value . toString () ));
4252 doc .setLength (0 );
4353 }
4454 }
0 commit comments