source: trunk/poppler/mypoppler/goo/GooString.h @ 257

Last change on this file since 257 was 257, checked in by Eugene Romanenko, 13 years ago

PDF plugin: Poppler library updated to version 0.10.0

File size: 5.2 KB
Line 
1//========================================================================
2//
3// GooString.h
4//
5// Simple variable-length string type.
6//
7// Copyright 1996-2003 Glyph & Cog, LLC
8//
9//========================================================================
10
11//========================================================================
12//
13// Modified under the Poppler project - http://poppler.freedesktop.org
14//
15// All changes made under the Poppler project to this file are licensed
16// under GPL version 2 or later
17//
18// Copyright (C) 2006 Kristian HÞgsberg <krh@redhat.com>
19// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
20//
21// To see a description of the changes please see the Changelog file that
22// came with your tarball or type make ChangeLog if you are building from git
23//
24//========================================================================
25
26#ifndef GooString_H
27#define GooString_H
28
29#ifdef USE_GCC_PRAGMAS
30#pragma interface
31#endif
32
33#include <stdarg.h>
34#include <stdlib.h> // for NULL
35#include "gtypes.h"
36
37class GooString {
38public:
39
40  // Create an empty string.
41  GooString();
42
43  // Create a string from a C string.
44  GooString(const char *sA);
45
46  // Create a string from <lengthA> chars at <sA>.  This string
47  // can contain null characters.
48  GooString(const char *sA, int lengthA);
49
50  // Create a string from <lengthA> chars at <idx> in <str>.
51  GooString(GooString *str, int idx, int lengthA);
52
53  // Set content of a string to concatination of <s1> and <s2>. They can both
54  // be NULL. if <s1Len> or <s2Len> is CALC_STRING_LEN, then length of the string
55  // will be calculated with strlen(). Otherwise we assume they are a valid
56  // length of string (or its substring)
57  GooString* Set(const char *s1, int s1Len=CALC_STRING_LEN, const char *s2=NULL, int s2Len=CALC_STRING_LEN);
58
59  // Copy a string.
60  GooString(GooString *str);
61  GooString *copy() { return new GooString(this); }
62
63  // Concatenate two strings.
64  GooString(GooString *str1, GooString *str2);
65
66  // Convert an integer to a string.
67  static GooString *fromInt(int x);
68
69  // Create a formatted string.  Similar to printf, but without the
70  // string overflow issues.  Formatting elements consist of:
71  //     {<arg>:[<width>][.<precision>]<type>}
72  // where:
73  // - <arg> is the argument number (arg 0 is the first argument
74  //   following the format string) -- NB: args must be first used in
75  //   order; they can be reused in any order
76  // - <width> is the field width -- negative to reverse the alignment;
77  //   starting with a leading zero to zero-fill (for integers)
78  // - <precision> is the number of digits to the right of the decimal
79  //   point (for floating point numbers)
80  // - <type> is one of:
81  //     d, x, o, b -- int in decimal, hex, octal, binary
82  //     ud, ux, uo, ub -- unsigned int
83  //     ld, lx, lo, lb, uld, ulx, ulo, ulb -- long, unsigned long
84  //     f, g -- double
85  //     c -- char
86  //     s -- string (char *)
87  //     t -- GooString *
88  //     w -- blank space; arg determines width
89  // To get literal curly braces, use {{ or }}.
90  static GooString *format(char *fmt, ...);
91  static GooString *formatv(char *fmt, va_list argList);
92
93  // Destructor.
94  ~GooString();
95
96  // Get length.
97  int getLength() { return length; }
98
99  // Get C string.
100  char *getCString() { return s; }
101
102  // Get <i>th character.
103  char getChar(int i) { return s[i]; }
104
105  // Change <i>th character.
106  void setChar(int i, char c) { s[i] = c; }
107
108  // Clear string to zero length.
109  GooString *clear();
110
111  // Append a character or string.
112  GooString *append(char c);
113  GooString *append(GooString *str);
114  GooString *append(const char *str, int lengthA=CALC_STRING_LEN);
115
116  // Append a formatted string.
117  GooString *appendf(char *fmt, ...);
118  GooString *appendfv(char *fmt, va_list argList);
119
120  // Insert a character or string.
121  GooString *insert(int i, char c);
122  GooString *insert(int i, GooString *str);
123  GooString *insert(int i, const char *str, int lengthA=CALC_STRING_LEN);
124
125  // Delete a character or range of characters.
126  GooString *del(int i, int n = 1);
127
128  // Convert string to all-upper/all-lower case.
129  GooString *upperCase();
130  GooString *lowerCase();
131
132  // Compare two strings:  -1:<  0:=  +1:>
133  int cmp(GooString *str);
134  int cmpN(GooString *str, int n);
135  int cmp(const char *sA);
136  int cmpN(const char *sA, int n);
137
138  GBool hasUnicodeMarker(void);
139
140private:
141  // you can tweak this number for a different speed/memory usage tradeoffs.
142  // In libc malloc() rounding is 16 so it's best to choose a value that
143  // results in sizeof(GooString) be a multiple of 16.
144  // 24 makes sizeof(GooString) to be 32.
145  static const int STR_STATIC_SIZE = 24;
146  // a special value telling that the length of the string is not given
147  // so it must be calculated from the strings
148  static const int CALC_STRING_LEN = -1;
149
150  int  roundedSize(int len);
151
152  char sStatic[STR_STATIC_SIZE];
153  int length;
154  char *s;
155
156  void resize(int newLength);
157  static void formatInt(long x, char *buf, int bufSize,
158                        GBool zeroFill, int width, int base,
159                        char **p, int *len);
160  static void formatUInt(Gulong x, char *buf, int bufSize,
161                         GBool zeroFill, int width, int base,
162                         char **p, int *len);
163  static void formatDouble(double x, char *buf, int bufSize, int prec,
164                           GBool trim, char **p, int *len);
165};
166
167#endif
Note: See TracBrowser for help on using the repository browser.