Cotix/cReddit — pull request #41 by DSMan195276 (2013-10-12 01:16:42+00:00)
Title: Refactor parser

A few changes here (Nothing very ground-breaking though). Most of it is just redesigning some code, not many changes that are noticeable externally.

The first patch redoes the Reddit EscCode parsing. Origionally, there were basically two functions which were duplicates of each-other, one for char* and one for wchar_t. They were also restricted to only internal library use. With this patch, the two separate versions are combined into one 'generic' version which works on both char and wchar_t strings, depending on a simple flag variable to decide which one to use. It also changes the functions to be accessible outside of the library, by making the parameter simply a text string, and it returns a new string that's parsed.

This change is worked in to the regular code by introducing a few new variables into the structs in reddit.h. Basically, the old names like 'selftext', 'title', are now copies of the unparsed text (Previously, there was no saved copy of the non-parsed text). A name in the form of 'selftextEsc' contains the char version of the parsed text. A version called 'wselftextEsc' contains the wchar_t version.

The second patch updates main.c to use the correct variables from the structs (Basically, switch from using the plain versions like 'selftext' to the wchar_t Esc versions, like 'wselftextEsc').

The third patch updates the token-parser to allow it to parse the wide-character strings automatically (It takes two extra pointers to the strings to store the parsed versions in, and then automatically parses the code and stores the strings). Previously, this functionality was simply being repeated in a few similar callbacks for each string member. Adding it into the token-parser keeps us from duplicating that code *every* time we add a new parsed string.