Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Private Attributes
CalculateUTF8Size Class Reference

A character sink (see |copy_string| in nsAlgorithm.h) for computing the number of bytes a UTF-16 would occupy in UTF-8. More...

#include <nsUTF8Utils.h>

List of all members.

Public Types

typedef nsAString::char_type value_type

Public Member Functions

 CalculateUTF8Size ()
size_t Size () const
PRUint32 NS_ALWAYS_INLINE write (const value_type *start, PRUint32 N)

Private Attributes

size_t mSize

Detailed Description

A character sink (see |copy_string| in nsAlgorithm.h) for computing the number of bytes a UTF-16 would occupy in UTF-8.

Definition at line 380 of file nsUTF8Utils.h.


Member Typedef Documentation

typedef nsAString::char_type CalculateUTF8Size::value_type

Definition at line 383 of file nsUTF8Utils.h.


Constructor & Destructor Documentation

Definition at line 385 of file nsUTF8Utils.h.

      : mSize(0) { }

Member Function Documentation

size_t CalculateUTF8Size::Size ( void  ) const [inline]

Definition at line 388 of file nsUTF8Utils.h.

{ return mSize; }

Here is the caller graph for this function:

Definition at line 390 of file nsUTF8Utils.h.

      {
        // Assume UCS2 surrogate pairs won't be spread across fragments.
        for (const value_type *p = start, *end = start + N; p < end; ++p )
          {
            value_type c = *p;
            if (! (c & 0xFF80)) // U+0000 - U+007F
              mSize += 1;
            else if (! (c & 0xF800)) // U+0100 - U+07FF
              mSize += 2;
            else if (0xD800 != (0xF800 & c)) // U+0800 - U+D7FF,U+E000 - U+FFFF
              mSize += 3;
            else if (0xD800 == (0xFC00 & c)) // U+D800 - U+DBFF
              {
                ++p;
                if (p == end)
                  {
                    NS_ERROR("Surrogate pair split between fragments");
                    return N;
                  }
                c = *p;

                if (0xDC00 == (0xFC00 & c))
                  mSize += 4;
                else
                  NS_ERROR("got a high Surrogate but no low surrogate");
              }
            else // U+DC00 - U+DFFF
              NS_ERROR("got a low Surrogate but no high surrogate");
          }

        return N;
      }

Member Data Documentation

size_t CalculateUTF8Size::mSize [private]

Definition at line 425 of file nsUTF8Utils.h.


The documentation for this class was generated from the following file: