Here are some regex script use in vim to help you translate objc code to cpp version.It is not perfect since it just could translate nearly 80% code correctly.
how to use it :
1.open mac terminal
2.run vim open the objec-code file
3.copy the regex below
4.click the edit->paste on the terminal menu
5.prees enter key
6.repeat step 4 - 5 seviral times
7.done
last ,if you have a more useful method to translate objc code to cpp code,please comment below,then I will recevied it in my email-box
12.24:
add nil -> NULL and Happy Christmas!
12.25:
Improve accuracy.
2012.4.26:
Add a line regex to Improve accuracy.
Amazing… Awesome work!
Some suggestions:
# and import > include
# remove brackets from function’s return value, like> bool, (void) -> void
# If we can add class name from @implementation ClassName to each function like ClaaName::foo would be greate, but seems unachievable via regex.
1.Thank you for reply Wang. my regex has some bug and I’m looking forward to some one wil give a more better one.
2.All your suggestions could be unachievable via regex but a bit tedious, since it’s just regex , if you know how to use regex in vim edit,you can achieve any you want by using regex step by step.
3.All my regex I think is not a finisher but a helper. It is suitable for local change and you know what are doing about.
Hi steve,
Thx for offering such a well written script.
I just test your script , but it not works very well.
today i update my regex and then you can integrate into your script.
btw, Since my regex can only deal with single line code per times in vim.
I’ve updated the script, and added a small 2nd script.
remember to `chmod +x` each script
scripts were tested using OSX terminal
objc2cpp.sh - does a find/replace on a single file passed in as argument
objc2all.sh - loops through the files in the current directory, then passes each to the objc2cpp.sh script
Usage: objc2cpp.sh [filename]
objc2all.sh - is a wrapper to call objc2cpp.sh for each file in the current directory
NOTE: If it doesn’t work for you still, let me know what OS and terminal / shell you are running. Could look at converting to Python to help make it more cross-platform. And I will continue to update it as I find better ways to translate code.