Adamic Tomislav wrote: > Hi > > I'm a bit puzzled with ANTLR API for ANTLR3_STRING... I need few > operations on strings and I could do it either by converting > ANTLR3_STRING into std::string (or std::wstring) or do it directly. > Well, I can't figure out either. So, let's say I want to create a copy > of some already existing ANTLR3_STRING. Is this the proper way of > doing it, so it doesn't leak memory: > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: > http://www.antlr.org/mailman/options/antlr-interest/your-email-address > These are just convenience methods for C programmers. If you are happy with the C++ libraries available to you, then just use the pointer and length fields (actually I think it is start and stop) fields to work with the string directly. The ANTLR3_STRING stuff will auto track memory usage and so on, but if you perform lots of string references then it can be a memory hog because it does not release anything until the parser is freed.
Get a token reference: mytok=TOKEN Then create a factory method or a function or whatever that takes a token pointer and creates your C++ string. Do not use the $text references as these will create ANTLR3_STRING that you don't need. Jim List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
