Syntax-Highlight-Universal

 view release on metacpan or  search on metacpan

colorer/unicode/Encodings.cpp  view on Meta::CPAN


#include<unicode/Encodings.h>
#include<unicode/x_encodings.h>

UnsupportedEncodingException::UnsupportedEncodingException(){};
UnsupportedEncodingException::UnsupportedEncodingException(const String& msg){
  message = new StringBuffer("UnsupportedEncodingException: ");
  message->append(msg);
}

const int Encodings::ENC_UTF8_BOM    = 0xBFBBEF;
const int Encodings::ENC_UTF16_BOM   = 0xFEFF;
const int Encodings::ENC_UTF16BE_BOM = 0xFFFE;
const int Encodings::ENC_UTF32_BOM   = 0x0000FEFF;
const int Encodings::ENC_UTF32BE_BOM = 0xFFFE0000;

const int Encodings::ENC_UTF32BE = (-6);
const int Encodings::ENC_UTF32   = (-5);
const int Encodings::ENC_UTF16BE = (-4);
const int Encodings::ENC_UTF16   = (-3);
const int Encodings::ENC_UTF8    = (-2);


#define ENC_UTF8_BOM    ((byte*)&Encodings::ENC_UTF8_BOM)
#define ENC_UTF16_BOM   ((byte*)&Encodings::ENC_UTF16_BOM)
#define ENC_UTF16BE_BOM ((byte*)&Encodings::ENC_UTF16BE_BOM)
#define ENC_UTF32_BOM   ((byte*)&Encodings::ENC_UTF32_BOM)
#define ENC_UTF32BE_BOM ((byte*)&Encodings::ENC_UTF32BE_BOM)
static byte *bomArray[5] = { ENC_UTF8_BOM, ENC_UTF16_BOM, ENC_UTF16BE_BOM, ENC_UTF32_BOM, ENC_UTF32BE_BOM };
static int bomArraySize[5] = { 3, 2, 2, 4, 4 };

byte* Encodings::getEncodingBOM(int encoding){
  if (encoding >= -1 || encoding < -6) throw UnsupportedEncodingException(DString("getEncodingBOM was called for bad encoding"));
  return bomArray[-encoding-2];
}

int Encodings::getEncodingBOMSize(int encoding){
  if (encoding >= -1 || encoding < -6) throw UnsupportedEncodingException(DString("getEncodingBOM was called for bad encoding"));
  return bomArraySize[-encoding-2];
}
int Encodings::isMultibyteEncoding(int encoding){
  return (encoding < -1);
}

int Encodings::getEncodingIndex(const char *enc){
  if (!enc) return -1;
  for(int i = 0; i < encAliasesNum; i++)
  if (!stricmp(arr_idxEncodings[i].name, enc)){

colorer/unicode/Encodings.h  view on Meta::CPAN

/** Encodings information.
    - All codepage definitions are read from list of ANSI -> Unicode
      associative files. These codepage files could be taken from
      www.unicode.org too.
    - Two-stage tables are used to access Unicode -> ANSI transformation.
    @ingroup unicode
*/
class Encodings{
public:
  // reverse order int integer notation!
  const static int ENC_UTF8_BOM;
  const static int ENC_UTF16_BOM;
  const static int ENC_UTF16BE_BOM;
  const static int ENC_UTF32_BOM;
  const static int ENC_UTF32BE_BOM;

  const static int ENC_UTF32BE;
  const static int ENC_UTF32;
  const static int ENC_UTF16BE;
  const static int ENC_UTF16;
  const static int ENC_UTF8;

  /** returns Byte Order Mark bytes for specified Unicode encoding */
  static byte* getEncodingBOM(int encoding);
  /** returns Byte Order Mark bytes <b>Length</b> for specified Unicode encoding */
  static int getEncodingBOMSize(int encoding);
  static int isMultibyteEncoding(int encoding);
  static int toBytes(int encoding, wchar, byte*);

  static char toChar(int, wchar);
  static wchar toWChar(int, char);

  static int getEncodingNamesNum();
  static int getDefaultEncodingIndex();
  static const char *getDefaultEncodingName();

colorer/xml/xmldom.cpp  view on Meta::CPAN

  entitiesHash.put(&DString("quot"), new SString("\""));
  entitiesHash.put(&DString("apos"), new SString("\'"));

  doc = newDocument();
  doc->line = 0;
  doc->pos = 0;

  ppos = opos = 0;
  src = DString(bytes, length, Encodings::getEncodingIndex(codepage));
  src_overflow = null;
  if (src[0] == Encodings::ENC_UTF16_BOM){
    ppos++;
  }

  try{
    consumeDocument();
  }catch(ParseException &e){
    free(doc);
    throw ParseException(*e.getMessage(), doc->line, doc->pos);
  }



( run in 0.368 second using v1.01-cache-2.11-cpan-131fc08a04b )