src/ast/rewriter/seq_rewriter.cpp
//  (str.replace s t t') is the string obtained by replacing the first occurrence 
//  of t in s, if any, by t'. Note that if t is empty, the result is to prepend
//  t' to s; also, if t does not occur in s then the result is s.
(str.replace s t t') is the string obtained by replacing the first occurrence
of t in s, if any, by t'. Note that if t is empty, the result is to prepend
t' to s; also, if t does not occur in s then the result is s.
( str . replace s t t ' ) is the string obtained by replacing the first occurrence of t in s if any by t ' . Note that if t is empty the result is to prepend t ' to s ; also if t does not occur in s then the result is s .
br_status seq_rewriter::mk_seq_replace(expr* a, expr* b, expr* c, expr_ref& result) {
    zstring s1, s2, s3;
    if (m_util.str.is_string(a, s1) && m_util.str.is_string(b, s2) && 
        m_util.str.is_string(c, s3)) {
        result = m_util.str.mk_string(s1.replace(s2, s3));
        return BR_DONE;
    }
    if (b == c) {
        result = a;
        return BR_DONE;
    }
    if (a == b) {
        result = c;
        return BR_DONE;
    }
    if (m_util.str.is_empty(b)) {
        result = m_util.str.mk_concat(c, a);
        return BR_REWRITE1;
    }
    m_lhs.reset();
    m_util.str.get_concat(a, m_lhs);
    if (m_lhs.empty()) {
        unsigned len = 0;
        m_util.str.get_concat(b, m_lhs);
        min_length(m_lhs.size(), m_lhs.c_ptr(), len);
        if (len > 0) {
            result = a;
            return BR_DONE;
        }
        return BR_FAILED;
    }
    if (m_lhs.get(0) == b) {
        m_lhs[0] = c;
        result = m_util.str.mk_concat(m_lhs.size(), m_lhs.c_ptr());
        return BR_REWRITE1;
    }
    if (m_util.str.is_string(b, s2) && m_util.str.is_string(c, s3) && 
        m_util.str.is_string(m_lhs.get(0), s1) && s1.contains(s2) ) {
        m_lhs[0] = m_util.str.mk_string(s1.replace(s2, s3));
        result = m_util.str.mk_concat(m_lhs.size(), m_lhs.c_ptr());
        return BR_REWRITE1;
    }
    return BR_FAILED;
}
br_status seq_rewriter :: mk_seq_replace ( expr * a , expr * b , expr * c , expr_ref & result ) { zstring s1 , s2 , s3 ; if ( m_util . str . is_string ( a , s1 ) && m_util . str . is_string ( b , s2 ) && m_util . str . is_string ( c , s3 ) ) { result = m_util . str . mk_string ( s1 . replace ( s2 , s3 ) ) ; return BR_DONE ; } if ( b == c ) { result = a ; return BR_DONE ; } if ( a == b ) { result = c ; return BR_DONE ; } if ( m_util . str . is_empty ( b ) ) { result = m_util . str . mk_concat ( c , a ) ; return BR_REWRITE1 ; } m_lhs . reset ( ) ; m_util . str . get_concat ( a , m_lhs ) ; if ( m_lhs . empty ( ) ) { unsigned len = 0 ; m_util . str . get_concat ( b , m_lhs ) ; min_length ( m_lhs . size ( ) , m_lhs . c_ptr ( ) , len ) ; if ( len > 0 ) { result = a ; return BR_DONE ; } return BR_FAILED ; } if ( m_lhs . get ( 0 ) == b ) { m_lhs [ 0 ] = c ; result = m_util . str . mk_concat ( m_lhs . size ( ) , m_lhs . c_ptr ( ) ) ; return BR_REWRITE1 ; } if ( m_util . str . is_string ( b , s2 ) && m_util . str . is_string ( c , s3 ) && m_util . str . is_string ( m_lhs . get ( 0 ) , s1 ) && s1 . contains ( s2 ) ) { m_lhs [ 0 ] = m_util . str . mk_string ( s1 . replace ( s2 , s3 ) ) ; result = m_util . str . mk_concat ( m_lhs . size ( ) , m_lhs . c_ptr ( ) ) ; return BR_REWRITE1 ; } return BR_FAILED ; }
(str.replace s t t') is the string obtained by replacing the first occurrence
of t in s, if any, by t'.
( str . replace s t t ' ) is the string obtained by replacing the first occurrence of t in s if any by t ' .
// a = "", |b| > 0 -> replace("",b,c) = "" // a := b + rest // a : a' + rest string, b is string, c is string, a' contains b