[poppler] poppler/poppler: UGooString.cc, NONE, 1.1 UGooString.h, NONE, 1.1

Albert Astals Cid aacid at freedesktop.org
Wed Jan 18 14:36:04 PST 2006


Update of /cvs/poppler/poppler/poppler
In directory gabe:/tmp/cvs-serv29685/poppler

Added Files:
	UGooString.cc UGooString.h 
Log Message:

as usual i foget some files


--- NEW FILE: UGooString.cc ---
//========================================================================
//
// UGooString.cc
//
// Unicode string
//
// Copyright 2005 Albert Astals Cid <aacid at kde.org>
//
//========================================================================

#include <string.h>

#include "goo/gmem.h"
#include "goo/GooString.h"
#include "PDFDocEncoding.h"
#include "UGooString.h"

UGooString::UGooString(Unicode *u, int l)
{
  s = u;
  length = l;
}

UGooString::UGooString(GooString &str)
{
  if ((str.getChar(0) & 0xff) == 0xfe && (str.getChar(1) & 0xff) == 0xff)
  {
    length = (str.getLength() - 2) / 2;
    s = (Unicode *)gmallocn(length, sizeof(Unicode));
    for (int j = 0; j < length; ++j) {
      s[j] = ((str.getChar(2 + 2*j) & 0xff) << 8) | (str.getChar(3 + 2*j) & 0xff);
    }
  } else
    initChar(str);
}

UGooString::UGooString(const UGooString &str)
{
  length = str.length;
  s = (Unicode *)gmallocn(length, sizeof(Unicode));
  memcpy(s, str.s, length * sizeof(Unicode));
}

UGooString::UGooString(const char *str)
{
  GooString aux(str);
  initChar(aux);
}

void UGooString::initChar(GooString &str)
{
  length = str.getLength();
  s = (Unicode *)gmallocn(length, sizeof(Unicode));
  for (int j = 0; j < length; ++j) {
    s[j] = pdfDocEncoding[str.getChar(j) & 0xff];
  }
}

UGooString::~UGooString()
{
  gfree(s);
}

int UGooString::cmp(UGooString *str) const
{
  int n1, n2, i, x;
  Unicode *p1, *p2;

  n1 = length;
  n2 = str->length;
  for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2; ++i, ++p1, ++p2) {
    x = *p1 - *p2;
    if (x != 0) {
      return x;
    }
  }
  return n1 - n2;
}

char *UGooString::getCString() const
{
  char *res = new char[length + 1];
  for (int i = 0; i < length; i++) res[i] = s[i];
  res[length] = '\0';
  return res;
}

--- NEW FILE: UGooString.h ---
//========================================================================
//
// UGooString.h
//
// Unicode string
//
// Copyright 2005 Albert Astals Cid <aacid at kde.org>
//
//========================================================================

#ifndef UGooString_H
#define UGooString_H

#include "CharTypes.h"

class GooString;

class UGooString
{
public:
  // Create an unicode string
  UGooString(Unicode *u, int l);

  // Create a unicode string from <str>.
  UGooString(GooString &str);

  // Copy the unicode string
  UGooString(const UGooString &str);

  // Create a unicode string from <str>.
  UGooString(const char *str);

  // Destructor.
  ~UGooString();

  // Get length.
  int getLength() const { return length; }

  // Compare two strings:  -1:<  0:=  +1:>
  int cmp(UGooString *str) const;

  // get the unicode
  Unicode *unicode() const { return s; }

  // get the const char*
  char *getCString() const;

private:
  void initChar(GooString &str);

  int length;
  Unicode *s;
};

#endif



More information about the poppler mailing list