ECode UriCodec::AppendEncoded( /* [in] */ IStringBuilder * builder, /* [in] */ const String& s, /* [in] */ ICharset* charset, /* [in] */ Boolean isPartiallyEncoded) { if (s.IsNull()) return E_NULL_POINTER_EXCEPTION; Int32 escapeStart = -1; AutoPtr<ArrayOf<Char32> > char32Array = s.GetChars(); for (Int32 i = 0; i < s.GetLength(); i++) { Char32 c = (*char32Array)[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || IsRetained(c) || (c == '%' && isPartiallyEncoded)) { if (escapeStart != -1) { AppendHex(builder, s.Substring(escapeStart, i), charset); escapeStart = -1; } if (c =='%' && isPartiallyEncoded){ builder->Append(s.Substring(i, Elastos::Core::Math::Min(i + 3, s.GetLength()))); i += 2; } else if (c == ' '){ builder->AppendChar('+'); } else{ builder->AppendChar(c); } } else if(escapeStart == -1) { escapeStart = i; } } if (escapeStart != -1) { AppendHex(builder, s.Substring(escapeStart, s.GetLength()), charset); } return NOERROR; }
ECode UriCodec::AppendHex( /* [in] */ IStringBuilder * builder, /* [in] */ const String& s, /* [in] */ ICharset* charset) { AutoPtr<ArrayOf<Byte> > bytes; bytes = GetBytes(s.string(), charset); assert(bytes != NULL); for (Int32 i = 0; i < bytes->GetLength(); ++i) { AppendHex(builder, (*bytes)[i]); } return NOERROR; }
std::string KeyWrapData( uint16_t keyLengthBytes, uint8_t keyRepeatValue, std::string keyStatusMsg ) { Buffer key(keyLengthBytes); key.GetWSlice().SetAllTo(keyRepeatValue); auto keyHex = ToHex(key.ToRSlice()); HexSequence statusBuffer(keyStatusMsg); Buffer lengthBuff(2); auto lenDest = lengthBuff.GetWSlice(); UInt16::WriteBuffer(lenDest, keyLengthBytes); auto lengthHex = ToHex(lengthBuff.ToRSlice()); return AppendHex({lengthHex, keyHex, keyHex, keyStatusMsg}); }