diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-20 04:45:31 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-20 04:45:31 +0000 |
commit | 09db0fb6eec99a7be47945edd5530a11216bae49 (patch) | |
tree | c3567ea0080c34f251382428f11662f2ac920318 /sca-cpp/trunk/kernel/value.hpp | |
parent | d96fc31da30e5d093862eeda6c94f625eb44449a (diff) |
Fix stack overflow on Mac OS X.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1172977 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/kernel/value.hpp')
-rw-r--r-- | sca-cpp/trunk/kernel/value.hpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/sca-cpp/trunk/kernel/value.hpp b/sca-cpp/trunk/kernel/value.hpp index 3e0dd0002f..886897f20f 100644 --- a/sca-cpp/trunk/kernel/value.hpp +++ b/sca-cpp/trunk/kernel/value.hpp @@ -448,15 +448,30 @@ const string watchValue(const value& v) { #endif /** + * Write an escape string to a buffer. + */ +const char* escapestr(const char* s, char* buf) { + if (*s == '\0') { + *buf = '\0'; + return buf; + } + if (*s == '\\' || *s == '"') { + *buf = '\\'; + *(buf + 1) = *s; + return escapestr(s + 1, buf + 2); + } + *buf = *s; + return escapestr(s + 1, buf + 1); +} + +/** * Write an escaped string value to a stream. */ -ostream& escvwrite(const char* s, ostream& out) { - if (*s == '\0') - return out; - if (*s == '\\' || *s == '"') - out << '\\'; - out << *s; - return escvwrite(s + 1, out); +ostream& escvwrite(const string& str, ostream& out) { + char* buf = gc_cnew(length(str) * 2 + 1); + escapestr(c_str(str), buf); + out << buf; + return out; } /** @@ -472,7 +487,7 @@ ostream& operator<<(ostream& out, const value& v) { return out << v.str()(); case value::String: out << '\"'; - escvwrite(c_str(v.str()()), out); + escvwrite(v.str()(), out); return out << '\"'; case value::Number: return out << v.num()(); |