diff --git a/src/util/string_constant.cpp b/src/util/string_constant.cpp index 14c5d8d09a5..25a0e7a5cf1 100644 --- a/src/util/string_constant.cpp +++ b/src/util/string_constant.cpp @@ -52,56 +52,12 @@ array_exprt string_constantt::to_array_expr() const int ch=i==string_size-1?0:str[i]; if(char_is_unsigned) - ch=(unsigned char)ch; + ch = (unsigned char)ch; + else + ch = (signed char)ch; - exprt &op=*it; - - op=from_integer(ch, char_type); - - if(ch>=32 && ch<=126) - { - std::string ch_str="'"; - if(ch=='\'' || ch=='\\') - ch_str+='\\'; - ch_str+=static_cast(ch); - ch_str+="'"; - } + *it = from_integer(ch, char_type); } return dest; } - -/// convert array constant into string -/// \return true on error -bool string_constantt::from_array_expr(const array_exprt &src) -{ - id(ID_string_constant); - type()=src.type(); - - const typet &subtype = to_array_type(type()).subtype(); - - // check subtype - if(subtype!=signed_char_type() && - subtype!=unsigned_char_type()) - return true; - - std::string value; - - forall_operands(it, src) - { - mp_integer int_value=0; - if(to_integer(*it, int_value)) - return true; - unsigned unsigned_value=integer2unsigned(int_value); - value+=static_cast(unsigned_value); - } - - // Drop the implicit zero at the end. - // Not clear what the semantics should be if it's not there. - if(!value.empty() && value[value.size()-1]==0) - value.resize(value.size()-1); - - set_value(value); - - return false; -}