blob: 7793bee61640912632b85c51b73aafccc446b5e2 [file] [log] [blame]
// GooString.h
// Simple variable-length string type.
// Copyright 1996-2003 Glyph & Cog, LLC
#ifndef GSTRING_H
#define GSTRING_H
#pragma interface
#include <string.h>
class GooString {
// Create an empty string.
// Create a string from a C string.
GooString(const char *sA);
// Create a string from <lengthA> chars at <sA>. This string
// can contain null characters.
GooString(const char *sA, int lengthA);
// Create a string from <lengthA> chars at <idx> in <str>.
GooString(GooString *str, int idx, int lengthA);
// Copy a string.
GooString(GooString *str);
GooString *copy() { return new GooString(this); }
// Concatenate two strings.
GooString(GooString *str1, GooString *str2);
// Convert an integer to a string.
static GooString *fromInt(int x);
// Destructor.
// Get length.
int getLength() { return length; }
// Get C string.
char *getCString() { return s; }
// Get <i>th character.
char getChar(int i) { return s[i]; }
// Change <i>th character.
void setChar(int i, char c) { s[i] = c; }
// Clear string to zero length.
GooString *clear();
// Append a character or string.
GooString *append(char c);
GooString *append(GooString *str);
GooString *append(const char *str);
GooString *append(const char *str, int lengthA);
// Insert a character or string.
GooString *insert(int i, char c);
GooString *insert(int i, GooString *str);
GooString *insert(int i, const char *str);
GooString *insert(int i, const char *str, int lengthA);
// Delete a character or range of characters.
GooString *del(int i, int n = 1);
// Convert string to all-upper/all-lower case.
GooString *upperCase();
GooString *lowerCase();
// Compare two strings: -1:< 0:= +1:>
// These functions assume the strings do not contain null characters.
int cmp(GooString *str) { return strcmp(s, str->getCString()); }
int cmpN(GooString *str, int n) { return strncmp(s, str->getCString(), n); }
int cmp(const char *sA) { return strcmp(s, sA); }
int cmpN(const char *sA, int n) { return strncmp(s, sA, n); }
int length;
char *s;
void resize(int length1);