Is it possible to make Ragel work over NSMutableString?
I would like to use Ragel to generate DFA to tokenize an NSMutableString. That "mutable" part means that I cannot use cStringUsingEncoding:
whenever single one character changes. As far as I can see, there are two problems:
The examples included with Ragel seem to use char *
to get a character even in Objective C. But I don't know how to get a pointer to the ever changing NSMutableString. Is it perhaps possible to force Ragel to use characterAtIndex:
instead? Wouldn't that be slow?
If I understand correctly, NSString might change its internal representation at runtime, i.e. it is not always UTF-16. For example, when it contains ASCII only, it uses single-byte encoding. But as soon as there appears a character outside the valid range, it switches to multi-byte encoding. Is it somehow possible to account for that in Ragel?
Off the top of my head, I'd use CFStringRef
directly, since it has CFStringCreateMutableWithExternalCharactersNoCopy, which allows you to declare your own buffer and explicitly disables the optimisations you're talking about.
Also, if you setup your externalCharactersAllocator
correctly, you might even benefit from toll-free bridging (though that might not work) so it doesn't get too messy for whatever mutates the string.