src/lib/INIReader.cpp
branchv_0
changeset 33 c9a158da6c32
parent 29 06aaad12c207
child 37 d89f621951ae
equal deleted inserted replaced
32:e72546725c77 33:c9a158da6c32
    56 
    56 
    57 	};
    57 	};
    58 
    58 
    59 	std::vector<ConfiguredDialect> dialects;
    59 	std::vector<ConfiguredDialect> dialects;
    60 
    60 
       
    61 	/**
       
    62 	 * If there is a „\“ backspace at the end of a physical line, the logical line continues on the next physical line.
       
    63 	 *
       
    64 	 * Disabling this option makes sense only if we also disable the unescaping processors (unescape-basic, unescape-backspace).
       
    65 	 * Otherwise they will complain about „Missing escape sequence“ because they got „\“ at the end of the value.
       
    66 	 */
       
    67 	bool allowLineContinuationsWithEscaping = true;
       
    68 
       
    69 	/**
       
    70 	 * If a line starts with a space, it is continuation of the previous line.
       
    71 	 * This rule conflicts with default ignorance of such insignificant whitespace and is quite specific to the Java MANIFEST.MF dialect.
       
    72 	 */
       
    73 	bool allowLineContinuationsWithSpace = false;
       
    74 
    61 	/** 
    75 	/** 
    62 	 * By default, we ignore all leading whitespace on continuing lines.
    76 	 * By default, we ignore all leading whitespace on continuing lines.
    63 	 * If there should be some spaces or tabs, they should be placed on the previous line before the „\“.
    77 	 * If there should be some spaces or tabs, they should be placed on the previous line before the „\“.
    64 	 * If a line break is desired, it should be written as \n (escaped) or the value should be quoted in " or '.
    78 	 * If a line break is desired, it should be written as \n (escaped) or the value should be quoted in " or '.
    65 	 * 
    79 	 * 
   186 	}
   200 	}
   187 
   201 
   188 	std::string readUntil(const std::string& until, bool* found = nullptr) {
   202 	std::string readUntil(const std::string& until, bool* found = nullptr) {
   189 		std::stringstream result;
   203 		std::stringstream result;
   190 
   204 
   191 		for (char ch = peek(); input.good() && !oneOf(ch, until); ch = peek()) {
   205 		for (char ch = peek(); input.good(); ch = peek()) {
   192 			if (ch == '\\') {
   206 			if (allowLineContinuationsWithSpace && ch == '\n') {
       
   207 				get();
       
   208 				ch = peek();
       
   209 				if (ch == ' ') get();
       
   210 				else if (ch == std::istream::traits_type::eof()) break;
       
   211 				else {
       
   212 					if (found) *found = true;
       
   213 					return result.str();
       
   214 				}
       
   215 			} else if (oneOf(ch, until)) {
       
   216 				break;
       
   217 			} else if (allowLineContinuationsWithEscaping && ch == '\\') {
   193 				get();
   218 				get();
   194 				ch = get();
   219 				ch = get();
   195 				if (oneOf(ch, until) && ch == '\n') processContinuingLine(result);
   220 				if (oneOf(ch, until) && ch == '\n') processContinuingLine(result);
   196 				else if (oneOf(ch, until)) result.put(ch);
   221 				else if (oneOf(ch, until)) result.put(ch);
   197 				else if (ch == std::istream::traits_type::eof()) break;
   222 				else if (ch == std::istream::traits_type::eof()) break;
   307 
   332 
   308 	INIReaderImpl(std::istream& input) : input(input) {
   333 	INIReaderImpl(std::istream& input) : input(input) {
   309 	}
   334 	}
   310 
   335 
   311 	void setOption(const std::string& uri, const std::string& value) override {
   336 	void setOption(const std::string& uri, const std::string& value) override {
   312 		if (uri == option::TrimContinuingLines) trimLeadingSpacesOnContinuingLines = parseBoolean(value); // TODO: continuing lines modes (enum), not just boolean
   337 		if (uri == option::AllowLineContinuationWithEscaping) allowLineContinuationsWithEscaping = parseBoolean(value);
       
   338 		else if (uri == option::AllowLineContinuationWithSpace) allowLineContinuationsWithSpace = parseBoolean(value);
       
   339 		else if (uri == option::TrimContinuingLines) trimLeadingSpacesOnContinuingLines = parseBoolean(value);
   313 		else if (uri == option::AllowSections) allowSections = parseBoolean(value);
   340 		else if (uri == option::AllowSections) allowSections = parseBoolean(value);
   314 		else if (uri == option::AllowSectionTags) allowSectionTags = parseBoolean(value);
   341 		else if (uri == option::AllowSectionTags) allowSectionTags = parseBoolean(value);
   315 		else if (uri == option::AllowSubKeys) allowSubKeys = parseBoolean(value);
   342 		else if (uri == option::AllowSubKeys) allowSubKeys = parseBoolean(value);
   316 		else if (uri == option::CommentSeparators) commentSeparators = value;
   343 		else if (uri == option::CommentSeparators) commentSeparators = value;
   317 		else if (uri == option::KeyValueSeparators) keyValueSeparators = value;
   344 		else if (uri == option::KeyValueSeparators) keyValueSeparators = value;