Identifier


#1

It would be great to have the ability to butcher a user-provided string into a valid identifier. Obviously it’s not particularly hard to do, but it would be neater if the Identifier class either (1) exposed the valid character set (so I don’t need to have a local literal copy) or (2) provided a static ‘createSafeString()’ style function.
Any chance of such loveliness? :slight_smile:


#2

If you look in the introjucer, there’s a makeValidIdentifier() function that I use for this kind of thing. Not sure if there could be a good general-purpose version of it, because you might have slightly different requirements, e.g. you might want a valid XML identifier, or a C++ identifier, or you might not want underscores, etc…


#3

You’re absolutely right! I just hate writing out literals like abcdefghijklmnopqrstuvwxyzABCDEFGHI…etc when I know they exist elsewhere in the code! :slight_smile: but of course there’s no reason to assume that such a string will [i]always[i] exist.
I shall just stop being lazy and write it!