Exemplo n.º 1
0
Arquivo: utf8.hpp Projeto: GavinHwa/oh
 size_t utf8_size(InputIterator first, InputIterator last, UTF16Type)
 {
     size_t len = 0;
     for (; first < last; ++first)
     {
         unsigned int c = *first;
         if (c < 0x80) // U+0000 - U+007F
         {
             len += 1;
         }
         else if (c < 0x0800) // U+0100 - U+07FF
         {
             len += 2;
         }
         else if (0xd800 != (0xf800 & c)) // U+0800 - U+D7FF, U+E000 - U+FFFF
         {
             len += 3;
         }
         else if (c < 0xdc00) // U+D800 - U+DBFF
         {
             ++first;
             if (first == last)
             {
                 HPROSE_THROW_EXCEPTION("Surrogate pair split between fragments");
             }
             c = *first;
             if (0xdc00 == (0xfc00 & c))
             {
                 len += 4;
             }
             else
             {
                 HPROSE_THROW_EXCEPTION("Got a high Surrogate but no low surrogate");
             }
         }
         else // U+DC00 - U+DFFF
         {
             HPROSE_THROW_EXCEPTION("got a low Surrogate but no high surrogate");
         }
     }
     return len;
 }
Exemplo n.º 2
0
 std::ostream & httpclient::get_output_stream(void * context)
 {
     if (context)
     {
         return (static_cast<httpcontext *>(context))->request_stream;
     }
     else
     {
         HPROSE_THROW_EXCEPTION("Can''t get output stream.");
     }
 }
Exemplo n.º 3
0
 std::istream & httpclient::get_input_stream(void * context)
 {
     if (context)
     {
         return (static_cast<httpcontext *>(context))->response_stream;
     }
     else
     {
         HPROSE_THROW_EXCEPTION("Can''t get input stream.");
     }
 }
Exemplo n.º 4
0
Arquivo: utf8.hpp Projeto: GavinHwa/oh
 size_t utf8_size(InputIterator first, InputIterator last, UTF32Type)
 {
     size_t len = 0;
     for (; first < last; ++first)
     {
         unsigned int c = *first;
         if (c < 0x80) // U+0000 - U+007F
         {
             len += 1;
         }
         else if (c < 0x0800) // U+0100 - U+07FF
         {
             len += 2;
         }
         else if (c < 0xd800) // U+0800 - U+D7FF
         {
             len += 3;
         }
         else if (c < 0xe000) // U+D800 - U+DFFF
         {
             HPROSE_THROW_EXCEPTION("Surrogate values are illegal");
         }
         else if (c < 0x10000) // U+E000 - U+FFFF
         {
             len += 3;
         }
         else if (c <  0x0010ffff)
         {
             len += 4;
         }
         else
         {
             HPROSE_THROW_EXCEPTION("Not a UTF-32 string");
         }
     }
     return len;
 }
Exemplo n.º 5
0
Arquivo: utf8.hpp Projeto: GavinHwa/oh
 size_t utf8_length(InputIterator first, InputIterator last, UTF16Type)
 {
     size_t len = 0;
     for (; first < last; ++len)
     {
         if (is_ascii(*first))
         {
             first += 1;
         }
         else if (is_2byte(*first))
         {
             first+= 2;
         }
         else if (is_3byte(*first))
         {
             first += 3;
         }
         else if (is_4byte(*first))
         {
             first += 4;
             ++len;
         }
         else if (is_5byte(*first))
         {
             first += 5;
         }
         else if (is_6byte(*first))
         {
             first += 6;
         }
         else
         {
             break;
         }
     }
     if (first != last)
     {
         HPROSE_THROW_EXCEPTION("Not a UTF-8 string");
     }
     return len;
 }
Exemplo n.º 6
0
 tm * get_local_tm(tm * ptm) const
 {
     if (ptm)
     {
     #if __STDC_WANT_LIB_EXT1__
         localtime_s(&time, ptm);
     #elif __STDC_WANT_SECURE_LIB__
         localtime_s(ptm, &time);
     #else
         *ptm = *localtime(&time);
     #endif
         return ptm;
     }
     else
     {
     #if (__STDC_WANT_LIB_EXT1__ || __STDC_WANT_SECURE_LIB__)
         HPROSE_THROW_EXCEPTION("Points to the buffer can't be NULL!");
     #else
         return localtime(&time);
     #endif
     }
 }