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

Last change on this file since 277 was 277, checked in by rbri, 11 years ago

PDF plugin: Poppler library updated to version 0.12.3

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