+ long number_of_quotes = 0;
+ long number_of_equals = 0;
+ bool has_open_bracket = false;
+ bool in_quotes = false;
+ error = false;
+ if (!buffer)
+ {
+ return "";
+ }
+ // firstly clean up the line by stripping spaces from the start and end and converting tabs to spaces
+ for (int d = 0; d < strlen(buffer); d++)
+ if ((buffer[d]) == 9)
+ buffer[d] = ' ';
+ while ((buffer[0] == ' ') && (strlen(buffer)>0)) buffer++;
+ while ((buffer[strlen(buffer)-1] == ' ') && (strlen(buffer)>0)) buffer[strlen(buffer)-1] = '\0';
+ // empty lines are syntactically valid
+ if (!strcmp(buffer,""))
+ return "";
+ else if (buffer[0] == '#')
+ return "";
+ for (int c = 0; c < strlen(buffer); c++)
+ {
+ // convert all spaces that are OUTSIDE quotes into hardspace (0xA0) as this will make them easier to
+ // search and replace later :)
+ if ((!in_quotes) && (buffer[c] == ' '))
+ buffer[c] = '\xA0';
+ if ((buffer[c] == '<') && (!in_quotes))
+ {
+ has_open_bracket = true;
+ if (strlen(buffer) == 1)
+ {
+ *errorstream << "Tag without identifier at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ else if ((tolower(buffer[c+1]) < 'a') || (tolower(buffer[c+1]) > 'z'))
+ {
+ *errorstream << "Invalid characters in identifier at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ }
+ if (buffer[c] == '"')
+ {
+ number_of_quotes++;
+ in_quotes = (!in_quotes);
+ }
+ if ((buffer[c] == '=') && (!in_quotes))
+ {
+ number_of_equals++;
+ if (strlen(buffer) == c)
+ {
+ *errorstream << "Variable without a value at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ else if (buffer[c+1] != '"')
+ {
+ *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ else if (!c)
+ {
+ *errorstream << "Value without a variable (line starts with '=') at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ else if (buffer[c-1] == '\xA0')
+ {
+ *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ }
+ }
+ // no quotes, and no equals. something freaky.
+ if ((!number_of_quotes) || (!number_of_equals) && (strlen(buffer)>2) && (buffer[0]=='<'))
+ {
+ *errorstream << "Malformed tag at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ // odd number of quotes. thats just wrong.
+ if ((number_of_quotes % 2) != 0)
+ {
+ *errorstream << "Missing \" at " << filename << ":" << linenumber << endl;
+ error = true;
+ return "";
+ }
+ if (number_of_equals < (number_of_quotes/2))
+ {
+ *errorstream << "Missing '=' at " << filename << ":" << linenumber << endl;
+ }
+ if (number_of_equals > (number_of_quotes/2))
+ {
+ *errorstream << "Too many '=' at " << filename << ":" << linenumber << endl;
+ }