gpt4 book ai didi

iphone - 自动将所有方法放入.h文件中

转载 作者:行者123 更新时间:2023-12-03 21:04:04 25 4
gpt4 key购买 nike

在实现文件 (.m) 中,我有 30.. 方法。如何将它们的描述(全部)自动放入 .h 文件中?

最佳答案

接缝很难用正则表达式正确完成,但你可以用 awk 完成:

https://gist.github.com/1771131

#!/usr/bin/env awk -f
# print class and instance methods declarations from implementation
# Usage: ./printmethods.awk class.m or awk -f printmethods.awk class.m

/^[[:space:]]*@implementation/ {
implementation = 1;
}

/^[[:space:]]*@end/ {
implementation = 0;
}

/^[[:space:]]*[\-\+]/ {
if(implementation) {
method = 1;
collect = "";
}
}

/[^[:space:]]/ {
if(implementation && method) {
p = index($0, "{");
if(p == 0) {
if(collect == "")
collect = $0
else
collect = collect $0 "\n";
} else {
method = 0;
# trim white space and "{" from line end
gsub("[\{[:space:]]*$", "", $0);
collect = collect $0;
# trim white space from start
gsub("^[[:space:]]*", "", collect);
print collect ";"
}
}
}

关于iphone - 自动将所有方法放入.h文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com