我正试图改变所有看起来像这样的名字:thisForExample
,将其改为:this_for_example
in Xcode with regex. 是否有任何人知道如何这样做?
I have tried with this: ([a-z][A-Z])*[a-z]?
but it does not find anything.
我正试图改变所有看起来像这样的名字:thisForExample
,将其改为:this_for_example
in Xcode with regex. 是否有任何人知道如何这样做?
I have tried with this: ([a-z][A-Z])*[a-z]?
but it does not find anything.
<>Perl 如果你坚持使用“Regex”作为替代模式,将是一个很好的工具。
l
=> change first char (of following match variable) to lower caseL
=> change all chars (of following match variable) to lower caseu
=> change single char (of following match variable) to upper caseU
=> change all chars (of following match variable) to upper caseIf all you care is to convert (simple/trivial!) variables and method names à la thisForExample
into this_for_example
.
For this a single regex like this would be sufficient:
echo thisForExample = orThisForExample();
| perl -pe s/(?<=[^A-Z])([A-Z]+)(?=[^A-Z])/_L1/g;
//output: "this_for_example = or_this_for_example();"
然而,一旦你再次希望像......这样的名字(公开的)出现。
fooURL = URLString + URL + someURLFunction();
......you。 http://www.ohchr.org。
让我们看看一下我们对此的表述:
echo fooURL = URLString + URL + someURLFunction();
| perl -pe s/(?<=[^A-Z])([A-Z]+)(?=[^A-Z])/_L1/g;
//output: "foo_url = _urlstring + _url + some_urlfunction();"
Pre脏?
And to make things even worse:
It is syntactically impossible to distinguish between a (quite common) variable name "URLString" and a class name "NSString".
Conclusion: Regex alone is pretty hack-ish and error prone for this kind of task. And simply unsufficient. And you don t want a single shell call to potentially mess up your entire code base, do you?
There is a reason why Xcode has a refactor tool that utilizes clang s grammar tree to differentiate between syntactically identical (pattern-wise at least) variable and class names.
This is a problem for context free languages, not regular languages. Hence regular expressions cannot deal with it. You d need a contect free grammar to generate a language tree, etc. (and at that time you ve just started building a compiler)
另外,为什么在“核心”下使用? 如果你重新使用X条码,你可能会在奥杰C(++)或类似的一条路上重新编码,因为使用 came具有常识。 案例。 也许还有 否则的话会仇恨你,使我们有一天处理你强调的ObjC/C/...守则。
<>替代答复:
In a comment answer to Paul R you said you were basically merging two projects, one with under_scored naming, one with camelCased naming.
I d advise you then to switch your under_scored code base to camelCase. For two reasons:
移至_号 案例较少的错误,反之亦然。 (前身是:在 came虫环境中,当然只有!) 如果你主要根据X条编码的精细编码处理,那也会发生同样的错误。 把它视为“可能打破的简单少法”;
引用我自己的回答:
[…] I and probably pretty much everybody else would hate you for making us one day deal with your underscored ObjC/C/… code. […]
Here is a simple regex for converting under_score to camelCase:
echo this_for_example = _leading_under_score + or_this_for_example();
| perl -pe s/(?<=[w])_([w])/u1/g;
//output: "thisForExample = _leadingUnderScore + orThisForExample();"
仅需要找到<代码>[a-z][A-Z][a-z]。
恢复替代程序是trick的,不过,你计划如何将任意的上层案件换成与其较低的案件等同。
诸如<代码>([a-zA-Z][a-z]+)+?
The process could like this: You get all the names to a file, there you automatically forge the replacement, and make (automatically) sed script to change one to another.
Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...
I m using Xcode on OSX to develop command line C applications. I would also like to use Instruments to profile and find memory leaks. However, I couldn t find a way to display the console when ...
Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...
I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....
This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...
我跑了X条码,试图把我的手套放在我的电话上。 I m 获取错误信息:“正在设计的方案没有运行”。
Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...
In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...