Update Regex, add pledit with quotes

This commit is contained in:
Ricky Miller 2018-02-12 11:17:01 -06:00 committed by Jordan Eldredge
parent eaf1bbe5c9
commit 5732baeb97
3 changed files with 22 additions and 1 deletions

View file

@ -0,0 +1,6 @@
[Text]
Normal= "#00FF00"
Current= '#FFFFFF'
NormalBG= "#000000"
SelectedBG= "#0000FF"
Font= "Ricky's cool font!"

View file

@ -78,7 +78,7 @@ export const parseIni = text => {
let section, match;
return text.split(/[\r\n]+/g).reduce((data, line) => {
if ((match = line.match(PROPERTY_REGEX)) && section != null) {
const value = match[2].replace(/("|')/gi, "");
const value = match[2].replace(/(^")|("$)|(^')|('$)/gi, "");
data[section][match[1].trim().toLowerCase()] = value;
} else if ((match = line.match(SECTION_REGEX))) {
section = match[1].trim().toLowerCase();

View file

@ -145,6 +145,21 @@ bar = baz
expect(actual).toEqual(expected);
});
it("can parse a pledit.txt file with quotes", () => {
const pledit = fixture("PLEDIT_WITH_QUOTES.TXT");
const actual = parseIni(pledit);
const expected = {
text: {
normal: "#00FF00",
current: "#FFFFFF",
normalbg: "#000000",
selectedbg: "#0000FF",
font: "Ricky's cool font!"
}
};
expect(actual).toEqual(expected);
});
it("allows quotes around values", () => {
const actual = parseIni(`
[foo]