X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/579ed52671d7f57366fd37cc90a76668d4b4d70c..283e7e33dbc363c7bba72e3838b5e0d61c92bf2b:/Output.cpp diff --git a/Output.cpp b/Output.cpp index 0728e82..3396b48 100644 --- a/Output.cpp +++ b/Output.cpp @@ -3,6 +3,9 @@ #include #include +#include +#include + _finline CYFlags operator ~(CYFlags rhs) { return static_cast(~static_cast(rhs)); } @@ -43,7 +46,7 @@ bool CYTrue::Value() const { void CYAddressOf::Output(std::ostream &out, CYFlags flags) const { rhs_->Output(out, 1, CYLeft(flags)); - out << ".$()"; + out << ".addressOf()"; } void CYArgument::Output(std::ostream &out) const { @@ -463,14 +466,15 @@ void CYSelectorPart::Output(std::ostream &out) const { void CYSend::Output(std::ostream &out, CYFlags flags) const { out << "objc_msgSend("; self_->Output(out, CYPA, CYNoFlags); - out << ",\""; + out << ","; + std::ostringstream name; for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_) if (argument->name_ != NULL) { - out << *argument->name_; + name << *argument->name_; if (argument->value_ != NULL) - out << ':'; + name << ':'; } - out << "\""; + out << reinterpret_cast(sel_registerName(name.str().c_str())); for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_) if (argument->value_ != NULL) { out << ","; @@ -495,10 +499,18 @@ void CYSource::Output(std::ostream &out, bool block) const { } void CYString::Output(std::ostream &out, CYFlags flags) const { - out << '\"'; + unsigned quot(0), apos(0); + for (const char *value(value_), *end(value_ + size_); value != end; ++value) + if (*value == '"') + ++quot; + else if (*value == '\'') + ++apos; + + bool single(quot > apos); + + out << (single ? '\'' : '"'); for (const char *value(value_), *end(value_ + size_); value != end; ++value) switch (*value) { - case '"': out << "\\\""; break; case '\\': out << "\\\\"; break; case '\b': out << "\\b"; break; case '\f': out << "\\f"; break; @@ -507,13 +519,25 @@ void CYString::Output(std::ostream &out, CYFlags flags) const { case '\t': out << "\\t"; break; case '\v': out << "\\v"; break; + case '"': + if (!single) + out << "\\\""; + else goto simple; + break; + + case '\'': + if (single) + out << "\\'"; + else goto simple; + break; + default: if (*value < 0x20 || *value >= 0x7f) out << "\\x" << std::setbase(16) << std::setw(2) << std::setfill('0') << unsigned(*value); - else + else simple: out << *value; } - out << '\"'; + out << (single ? '\'' : '"'); } void CYSwitch::Output(std::ostream &out) const {