Sign in to follow this  

Regular expression to find hard coded strings

This topic is 3294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi - I'm preparing to do some localization work on a rather large project composed of C++ and C# code. The initial step is going to be moving all the hard coded strings into a resource file. I'm hoping someone else who has had to go through the pains of tracking down hard coded resources can help me out. Does anyone know of a good regular expression (or other tool) that can find the majority of hard coded strings in a large code base? I'm hoping for something that can exclude hard coded strings like: #include "some_header.h" /* This project has "strings" in comments */ // "Arg" DEBUG("Some debugging...") Any help would be greatly appreciated! --Andrew

Share this post


Link to post
Share on other sites
Quote:
Original post by TruckMack33
I'm not sure it's possible. Your going to need to keep names to the strings that you move. It's possible to find the strings but not sure if it's possible to give each an unique name.


At the moment I'm just concerned with tracking down all the strings. I'll worry about actually moving them once I know where they are.

Share this post


Link to post
Share on other sites
Quote:
Original post by agottem
I'm preparing to do some localization work on a rather large project composed of C++ and C# code. The initial step is going to be moving all the hard coded strings into a resource file. I'm hoping someone else who has had to go through the pains of tracking down hard coded resources can help me out.
I am aware that it doesn't help you here, but this is a great example of why you should think about localisation from the beginning [smile]

Apple has a pretty simple system, where each string constant that should be localised is wrapped in a NSLocalized("string") macro, which handles loading the correct version of the string, and a simple command line tool that searches for the macro and extracts the wrapped strings.

Share this post


Link to post
Share on other sites
In a VS2005 project, I have a function CAtlString LocalString(const CAtlString& english) that I wrap all of my user facing strings in. I use this regex to find string literals not enclosed by this function:

~(LocalString|include )\(\".*\"

This uses the VS internal dialect of regular expressions, and is far from perfect, for example:

- It will find _T(“”) but not L””
- It won’t find _T( “”) or _T (“)

Share this post


Link to post
Share on other sites
Why not just make your own little script/app which trawls a directory and sub-directories for source files and interpret them?


Look for strings
if found
if(CheckAgainstIgnoreList)
Continue with interpretation of file
else
Write source file and line number to log


The ignore list would contain stuff like #include and so on..

Share this post


Link to post
Share on other sites

This topic is 3294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this