作用:固定格式的文档生成属性声明
作用:固定格式的文档生成属性声明
作用:固定格式的文档生成属性声明
后台的文档,从网页上复制下来编程下面这个样子,
账户名称 accountName string 是 eg:微信
账户昵称 nickname string 是 eg:你大哥
通过awk命令可以重新组织这些信息,将其转化为属性声明。
awk '$3 > 0 { if ($3 == "string") print "/* "$1" "$5" */""\n@property (nonatomic, copy) NSString *"$2";";
else if ($3 == "String") print "/* "$1" "$5" */""\n@property (nonatomic, copy) NSString *"$2";";
else if ($3 == "Double") print "/* "$1" "$5" */""\n@property (nonatomic, assign) double "$2";";
else if ($3 == "double") print "/* "$1" "$5" */""\n@property (nonatomic, assign) double "$2";";
else if ($3 == "Date") print "/* "$1" "$5" */""\n@property (nonatomic, copy) NSString *"$2";";
else if ($3 == "date") print "/* "$1" "$5" */""\n@property (nonatomic, copy) NSString *"$2";";
else if ($3 == "Integer") print "/* "$1" "$5" */""\n@property (nonatomic, assign) NSInteger "$2";";
else if ($3 == "long") print "/*"$1 " "$5" */""\n@property (nonatomic, assign) NSInteger "$2";";
else if ($3 == "boolean") print "/* "$1" "$5" */""\n@property (nonatomic, assign) BOOL "$2";";
else if ($3 == "list") print "/* "$1" "$5" */""\n@property (nonatomic, strong) NSArray *"$2";";
else if ($3 == "List") print "/* "$1" "$5" */""\n@property (nonatomic, strong) NSArray *"$2";";
}' $1
将上面的内容保存为 doctoproperty.sh
调用sh doctoproperty.sh
输出
/* 账户名称 eg:微信 */
@property (nonatomic, copy) NSString *accountName;
/* 账户昵称 eg:你大哥 */
@property (nonatomic, copy) NSString *nickname;
网友评论