是否有一种简单的方法可以从C文件中提取assert函数的内部?
例如-
struct TextTransitionView: View {
@State var isValid = false
@State var show = false
var body: some View {
VStack {
Spacer()
if show {
Text("TEXT").transition(slideTransition)
}
Spacer()
Text("Move to \(isValid ? "right" : "left")")
Button("Toggle isValid") {
self.isValid.toggle()
}
Button("Toggle show") {
withAnimation { self.show.toggle() }
}
Button("Toggle isValid and show") {
withAnimation {
self.isValid.toggle()
self.show.toggle()
}
}
}
}
var slideTransition: AnyTransition {
let removal = isValid ? AnyTransition.move(edge: .trailing) : AnyTransition.move(edge: .leading)
return .asymmetric(insertion: .identity, removal: removal)
}
}
输出应为-
assert(cred->keytab == NULL);
/*
assert(1==1);
*/
我正在为断言函数寻找类似xgettext的东西。
答案 0 :(得分:2)
只需使用预处理器,它将显示在stderr上:
#undef assert(x)
int main(void)
{
int x=1;
assert(x==1);
return 0;
}
$ cc -Wall assertz.c
warning: extra tokens at end of #undef directive [enabled by default]
#undef assert(x)
^
assertz.c: In function ‘main’:
assertz.c:8:1: warning: implicit declaration of function ‘assert’ [-Wimplicit-function-declaration]
assert(x==1);
^
答案 1 :(得分:2)
让处理器摆脱评论该怎么办?
gcc -E prog.c -fpreprocessed | \
sed -re 's/^.*assert[ \t]*[(](.*)[)].*$/\1/;t;d'
答案 2 :(得分:1)
您可以使用bundle.get()
(如果可以的话)进行此操作,这也可以确保assert函数出现在注释中时会跳过它。
@SessionScoped
public class UserBean implements Serializable {
@Inject
private FacesContext context;
// ...
public void someAction() {
ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");
String message = bundle.getString("someLabel");
// ...
}
}