【发布时间】:2017-10-02 09:17:10
【问题描述】:
让 s1 是 Z3Str 中的任意字符串。 我可以检查其中的第三个字符是否是小写字母:
(declare-const s1 String)
(assert (= s1 "74b\x00!!###$$"))
(assert (str.in.re (str.at s1 2) (re.range "a" "z")))
(check-sat)
(get-value (s1))
现在假设确实如此,我想替换第三个字母 大写(新字符串 s2 将包含替换的版本)。受标准编程语言的启发, 我可能想做这样的事情:
(declare-const s1 String)
(declare-const s2 String)
(declare-const b1 Bool)
(assert (= s1 "74b\x00!!###$$"))
(assert (= b1 (str.in.re (str.at s1 2) (re.range "a" "z"))))
(assert (= (str.substr s2 0 2) (str.substr s1 0 2)))
(assert (= (str.substr s2 3 8) (str.substr s1 3 8)))
(assert (= (str.len s2) (str.len s1)))
(assert (= (str.at s2 2) (ite b1 (- (str.at s1 2) 32) (str.at s1 2))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 32 = 'a'-'A'
(check-sat)
(get-value (s1 s2 b1))
但是,当然,由于类型的原因,这不起作用:
(error "line 9 column 52: Sort mismatch at argument #1 for function
(declare-fun - (Int Int) Int) supplied sort is String")
是否有任何直接的方法来处理小数 Z3 字符串中字符的值?我的意思是除了 all 小写字母上的巨大 switch-case ... 似乎有一些希望,因为 API 确实支持 "\x61" 作为 "a" 的替代表示。非常感谢任何帮助,谢谢!
【问题讨论】: