result_t gd_base::color(const char *color, int32_t &retVal) { if (*color == '#') color ++; if (!qisxdigit(color[0]) || !qisxdigit(color[1]) || !qisxdigit(color[2])) return CHECK_ERROR(CALL_E_INVALIDARG); if (!color[3]) retVal = gdTrueColor(qhex(color[0]) * 17, qhex(color[1]) * 17, qhex(color[2]) * 17); else { if (!qisxdigit(color[3]) || !qisxdigit(color[4]) || !qisxdigit(color[5]) || color[6]) return CHECK_ERROR(CALL_E_INVALIDARG); retVal = gdTrueColor((qhex(color[0]) << 4) | qhex(color[1]), (qhex(color[2]) << 4) | qhex(color[3]), (qhex(color[4]) << 4) | qhex(color[5])); } return 0; }
static int32_t chunk_body(AsyncState* pState, int32_t n) { asyncReadFrom* pThis = (asyncReadFrom*)pState; _parser p(pThis->m_strLine); char ch; int64_t sz = 0; p.skipSpace(); if (!qisxdigit(p.get())) return CHECK_ERROR(Runtime::setError("HttpMessage: bad chunk size.")); while (qisxdigit(ch = p.get())) { sz = (sz << 4) + qhex(ch); p.skip(); } if (sz) { if (pThis->m_pThis->m_maxBodySize >= 0 && sz + pThis->m_contentLength > pThis->m_pThis->m_maxBodySize * 1024 * 1024) return CHECK_ERROR(Runtime::setError("HttpMessage: body is too huge.")); pThis->set(chunk_body_end); return pThis->m_stm->copyTo(pThis->m_body, sz, pThis->m_copySize, pThis); } pThis->set(chunk_end); return pThis->m_stm->readLine(HTTP_MAX_LINE, pThis->m_strLine, pThis); }
result_t ParseJsonString(v8::Local<v8::Value> &retVal) { wstring str; Advance(); while (c0_ != '"') { if (c0_ >= 0 && c0_ < 0x20) return ReportUnexpectedCharacter(); if (c0_ != '\\') { int32_t beg_pos = position_; while (c0_ != '"' && c0_ != '\\') { Advance(); if (c0_ >= 0 && c0_ < 0x20) return ReportUnexpectedCharacter(); } str.append(utf8to16String(source_ + beg_pos, position_ - beg_pos)); } else { Advance(); switch (c0_) { case '"': case '\\': case '/': str.append(1, c0_); break; case 'b': str.append(1, '\x08'); break; case 'f': str.append(1, '\x0c'); break; case 'n': str.append(1, '\x0a'); break; case 'r': str.append(1, '\x0d'); break; case 't': str.append(1, '\x09'); break; case 'u': { uint16_t value = 0; for (int32_t i = 0; i < 4; i++) { Advance(); if (!qisxdigit(c0_)) return ReportUnexpectedCharacter(); value = value * 16 + qhex(c0_); } str.append(1, value); break; } default: return ReportUnexpectedCharacter(); } Advance(); } } AdvanceSkipWhitespace(); retVal = v8::String::NewFromTwoByte(isolate->m_isolate, (const uint16_t*)str.c_str(), v8::String::kNormalString, (int32_t) str.length()); return 0; }