VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
static Dictionary<string, string> AVR.Core.AVR_SettingsParser.ParseSettings ( string  filepath,
Dictionary< string, string >  entries = null 
)
inlinestatic

Parse a single given settings-file.

Parameters
filepathPath of the file in question
entriespre-existing entries to add to. Duplicates will be overwritten.
Returns
Dictionary containing all settings from entries as well as the given file.

Definition at line 36 of file AVR_SettingsParser.cs.

36  {
37  AVR.Core.AVR_DevConsole.print("Parsing settingsfile: "+filepath);
38  string content = "";
39  try {
40  content = File.ReadAllText(filepath);
41  } catch(System.Exception) {
42  AVR.Core.AVR_DevConsole.error("Could not open settings file: " + filepath);
43  return entries;
44  }
45 
46  //First we remove all the comments (From hashtag to newline. TODO: Does this even work on Linux/MAC?
47  content = Regex.Replace(content, "#.*(\\r\\n|\\n|\\r)", "");
48 
49  //This regex splits the input at whitespaces, only if they are followed by an even number of quotation marks. See: https://stackoverflow.com/questions/25477562/split-java-string-by-space-and-not-by-double-quotation-that-includes-space
50  List<string> tokens = new List<string>(Regex.Split(content, "(?<!\\G\\S{0,99999}[\"'].{0,99999})\\s|(?<=\\G\\S{0,99999}\".{0,99999}\"\\S{0,99999})\\s|(?<=\\G\\S{0,99999}'.{0,99999}'\\S{0,99999})\\s"));
51 
52  // Clean up: (Delete empty tokens)
53  for(int i=0; i<tokens.Count; i++) {
54  tokens[i] = tokens[i].Trim().Trim('\"');
55  if(tokens[i].Length<1) {
56  tokens.RemoveAt(i);
57  i--;
58  }
59  }
60 
61  // Parse tokens
62  if(entries==null) entries = new Dictionary<string, string>();
63  parseDepth("", 0, tokens, entries);
64 
65  return entries;
66  }
static int parseDepth(string context, int i, List< string > content, Dictionary< string, string > entries)