Regex on the iPhone
John Engelhart wrote a nice piece of code, RegexKitLite, that allows regex programming on the iPhone. RegexKitLite is part of his larger RegexKit project.
There is something funky about how the simulator and device SDKs work with respect to how this code pulls in header files, however. I had to insert an #ifdef as a hack to get the code to work on a real iPhone device. The code works as-is if running in the simulator. Here is the mod, to RegexKitLite.m:
#ifdef iPhone
else { if((splitStrings = rkl_realloc(&scratchBuffer[1], splitStringsSize, (NSUInteger)1)) == NULL) { goto exitNow; } }
#else
else { if((splitStrings = rkl_realloc(&scratchBuffer[1], splitStringsSize, (NSUInteger)NSScannedOption)) == NULL) { goto exitNow; } }
#endif
near the original line 579.
October 21, 2008 update John Engelhart sent me a note indicating that v2.2 of RegexKitLite is available, and that this version probably doesn’t need this #ifdef. He was right: I tested my original simple test code against v2.2, and it seems to work fine. Thanks, John.