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

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

PDF plugin: poppler library updated to version 0.8.3

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