Download mychar 에서 모든 프로그램들을 하나의 tar.gz 화일로 다운로드받을 수 있다. 이 화일을 받으려면 웹브라우저에서 이 화일을 'Text' 타입으로 저장한다.
//*****************************************************************
//저작권은 GNU/GPL 에 있지만 저자의 이름과 이메일은 모든 복사본에
//포함시켜야 한다.
//저자: Al Dev 이메일: alavoor@yahoo.com
//*****************************************************************
//메모리유출을 방지하기위해서는 - a char class to manage character
//variables
//char[] 혹은 char *대신 mychar 나 string class 를 사용하는 것이 좋다.
#ifndef __MYCHAR_H_
#define __MYCHAR_H_
//#include <iostream> // iostream은 프로그램이 커지니까 사용하지 않는다.
//#include <stdlib.h> //free() 와malloc() 를 쓰기위해
#include <string.h> // for strcpy()
#include <ctype.h> // for isspace()
#include <stdio.h> // for sprintf()
#include <list.h> // for sprintf()
#include <math.h> // for modf(), rint()
#include "my_malloc.h"
#include "debug.h" // debug_(name, value) debug2_(name, value, LOG_YES)
const short INITIAL_SIZE = 50;
const short NUMBER_LENGTH = 70;
// 최소한의 함수와 변수를 가진 작은 클래스 (class)
// This class to be kept small... 이 클래스는 계속 작게 유지될것이다.
class mychar
{
public:
mychar();
mychar(char bb[]); // needed by operator+
mychar(int bb); // needed by operator+
mychar(unsigned long bb); // needed by operator+
mychar(float bb); // needed by operator+
mychar(double bb); // needed by operator+
mychar(const mychar & rhs); // Copy Constructor needed by operator+
~mychar();
char *val;
unsigned long length() { return strlen(val); }
void ltrim();
void rtrim();
void trim();
void chop();
void to_upper();
void to_lower();
void roundf(float input_val, short precision);
void decompose_float(long *integral, long *fraction);
void roundd(double input_val, short precision);
void decompose_double(long *integral, long *fraction);
long pos(char substr[], unsigned long start);
void explode(char *seperator);
void implode(char *glue);
void join(char *glue);
void repeat(char *input, unsigned int multiplier);
void reverse();
void replace(char *needle, char *str);
void str_tr(char *from, char *to);
void center(int length, char padchar = ' ');
void space(int number = 0, char padchar = ' ');
void xrange(char start, char end);
void compress(char *list);
void delstr(int start, int length);
void insert(char *newstr, int start = 0, int length = 0, char padchar = ' ');
void left(int length = 0, char padchar = ' ');
void right(int length = 0, char padchar = ' ');
void overlay(char *newstr, int start = 0, int length = 0, char padchar = ' ');
mychar substr(int start, int length = 0);
mychar at(char *regx); // matches first match of regx
mychar before(char *regx); // returns string before regx
mychar after(char *regx); // returns string after regx
bool isnull();
void clear();
// All Operators ...
mychar operator+ (const mychar & rhs);
friend mychar operator+ (const mychar & lhs, const mychar & rhs);
mychar& operator+= (const mychar & rhs); // using reference will be faster
mychar& operator= (const mychar & rhs); // using reference will be faster
bool operator== (const mychar & rhs); // using reference will be faster
bool operator== (const char *rhs);
bool operator!= (const mychar & rhs);
bool operator!= (const char *rhs);
static list<mychar> explodeH; // list head
private:
//static mychar *global_mychar; // for use in add operator
//inline void free_glob(mychar **aa);
void str_cpy(char bb[]);
void str_cpy(int bb); // itoa
void str_cpy(unsigned long bb);
void str_cpy(float bb); // itof
void str_cat(char bb[]);
void str_cat(int bb);
void str_cat(unsigned long bb);
void str_cat(float bb);
bool equalto(const mychar & rhs, bool type = false);
bool equalto(const char *rhs, bool type = false);
};
// Global variables are defined in mychar.cpp
#endif // __MYCHAR_H_