registering types and creators, minor fixes and improvements
[quarnos.git] / libs / string.cpp
blob6e4c60f94951342c9f60ef1722932d3b877f88e9
1 #include "string.h"
3 string::string(char *text) {
4 data = new char[strlen(text)];
7 string::string() : data((char*)0) {}
9 string::~string() {
10 if (data)
11 delete data;
14 int string::length() const {
15 return strlen(data);
18 char &string::operator[](int index) {
19 if (index < length())
20 return data[index];
21 else
22 return error;
25 bool string::operator==(char *x) {
26 if (!strcmp(data, x))
27 return true;
28 else
29 return false;
32 bool string::operator==(string &x) {
33 if (!strcmp(data, x.data))
34 return true;
35 else
36 return false;
39 string::operator char*() {
40 return data;
43 int strlen(const char *a) {
44 int i;
45 for (i = 0; a[i]; i++);
46 return i + 1;
49 int strcmp(const char *a,const char *b) {
50 int i;
51 for (i = 0; a[i] && b[i] && a[i] == b[i]; i++);
52 if (a[i] != b[i]) return 1;
53 return 0;
56 int strncmp(const char *a,const char *b, int n) {
57 int i;
58 for (i = 0; a[i] && b[i] && a[i] == b[i] && i < n; i++);
59 if (a[i] != b[i] && i != n) return 1;
60 return 0;
63 char *strcat(char *a, const char *b) {
64 return strcpy(&(a[strlen(a)]), b);
67 char *strcpy(char *a, const char *b) {
68 return (char*)memcpy((void*)a, (const void *)b, strlen(b));
71 void *memcpy(void * a, const void * b, int count) {
72 for (int i = 0; i < count; i++)
73 ((char *)a)[i] = ((const char *)b)[i];
74 return a;
77 void *memset(void *a, int sign, int count) {
78 for (int i = 0; i < count; i++)
79 ((unsigned char *)a)[i] = (unsigned char)sign;
80 return a;