Ejemplo n.º 1
0
void UEscape::encode(const unsigned char* s, uint32_t n, UString& buffer, bool json)
{
   U_TRACE(0, "UEscape::encode(%.*S,%u,%.*S,%b)", n, s, n, U_STRING_TO_TRACE(buffer), json)

   U_ASSERT(buffer.capacity() >= n)

   uint32_t sz  = buffer.size(),
            pos = u_escape_encode(s, n, buffer.c_pointer(sz), buffer.space(), json);

   buffer.size_adjust(sz + pos);
}
Ejemplo n.º 2
0
U_EXPORT ostream& operator<<(ostream& os, const UXMLElement& e)
{
   U_TRACE(0+256, "UXMLElement::operator<<(%p,%p)", &os, &e)

   // encode the element name

   os.put('<');

   if (e.namespaceName)
      {
      os << e.namespaceName;

      os.put(':');
      }

   os << e.accessorName;

   os.put(' ');

   // encode the element's attributes

   os << e.attributeContainer;

   // terminate the element declaration

   os.put(' ');
   os.put('>');

   if (e.value)
      {
      (void) os.write(U_CONSTANT_TO_PARAM(" VALUE = "));

      char buffer[4096];
      uint32_t len = u_escape_encode((const unsigned char*)U_STRING_TO_PARAM(e.value), buffer, sizeof(buffer), false);

      (void) os.write(buffer, len);
      }

   return os;
}
Ejemplo n.º 3
0
void UEscape::encode(const UString& s, UString& buffer, char before, char after)
{
   U_TRACE(0, "UEscape::encode(%.*S,%.*S,%C,%C)", U_STRING_TO_TRACE(s), U_STRING_TO_TRACE(buffer), before, after)

   U_INTERNAL_ASSERT_DIFFERS(after, '\0')
   U_ASSERT(buffer.capacity() >= s.size())

   uint32_t sz = buffer.size();
   char* ptr   = buffer.c_pointer(sz);

   if (before)
      {
      ++sz;

      *ptr++ = before;
      }

   uint32_t pos = u_escape_encode((const unsigned char*)U_STRING_TO_PARAM(s), ptr, buffer.space(), true);

   ptr[pos] = after;

   buffer.size_adjust(sz + 1 + pos);
}