gen_stri.h

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 593 行 · 第 1/2 页

H
593
字号
// Input:      None
// Output:     Maximum number of characters before growth is required

inline long CoolGen_String::capacity() const {
  return (this->p->size-1);                     
}


// set_alloc_size -- Set the default allocation size growth rate
// Input:            Growth size in number of elements
// Output:           None

inline void CoolGen_String::set_alloc_size (int n) {
#if ERROR_CHECKING
  if (n < 0)                                    // If negative growth size
    this->size_error (n);                       // Raise exception
#endif
  this->alloc_size_s = n;                       // Set growth size
}


// set_growth_ratio -- Set the growth percentage for this instance of String
// Input:              Percentage growth rat
// Output:             None

inline void CoolGen_String::set_growth_ratio (float ratio) {
#if ERROR_CHECKING
  if (ratio <= 0.0)                             // If positive growth factor
    this->ratio_error (ratio);                  // Raise exception
#endif
  this->growth_ratio = ratio;                   // Set growth size
}


// operator const char* -- Provide an accessor to the character pointer
// Input:            this* 
// Output:           this->str character pointer
inline CoolGen_String::operator const char*() const {
  return (this->str);
}

// start -- Return the zero-relative start index of regular expression match
// Input:   None
// Output:  Start index into string

inline long CoolGen_String::start () {
  return (this->rgexp_index + this->rgexp->start ());
}


// End -- Return the zero-relative end index of the regular expression match
// Input:   None
// Output:  End index into string

inline long CoolGen_String::end () {
  return (this->rgexp_index + this->rgexp->end ());
}


// is_valid -- Returns the validity of the regular expression
// Input:      None
// Output:     TRUE/FALSE

inline Boolean CoolGen_String::is_valid () {
  return (this->rgexp != NULL) &&               // If a Regexp object
         this->rgexp->is_valid ();              // return Regexp status
}


// operator= -- Assignment to a single character: x = 'A';
// Input:       Single character
// Output:      CoolGen_String object containing character string

inline CoolGen_String& CoolGen_String::operator= (char c) {
  return (strcpy (*this, c));                   
}


// operator= -- Assignment to a character string: x = "ABCDEFG";
// Input:       Character string
// Output:      CoolGen_String object containing character string

inline CoolGen_String& CoolGen_String::operator= (const char* c) {
  return (strcpy (*this, c));                   
}


// operator= -- Assignment to another CoolGen_String: x = y;
// Input:       Reference to CoolGen_String object
// Output:      CoolGen_String object sharing memory with other CoolGen_String

inline CoolGen_String& CoolGen_String::operator= (const CoolGen_String& s) {
  return (strcpy (*this, s));                   
}


// operator+= -- Concatenation of a character: x += 'A';
// Input:        Character
// Output:       CoolGen_String object concatenated with character

inline CoolGen_String& CoolGen_String::operator+= (char c) {
  return (strcat (*this, c));                   
}

// operator+ -- String concatenation of a character: y = x + 'A';
// Input:       Character
// Output:      new CoolGen_String object concatenated with character

inline CoolGen_String operator+ (const CoolGen_String& s, char c) {
  CoolGen_String temp(s);                       // temporary copy of s
  temp += c;                                    // mutate temp with += c
  return temp;                                  // return new copy by value
}

// operator+= -- Concatenation of a character string: x += "ABCDEFG";
// Input:        Character string
// Output:       CoolGen_String object concatenated with character string

inline CoolGen_String& CoolGen_String::operator+= (const char* c) {
  return (strcat (*this, c));                   
}


// operator+ -- String concatenation of a character string: y = x + "ABCDEFG";
// Input:       Character string
// Output:      new CoolGen_String object concatenated with character string

inline CoolGen_String operator+ (const CoolGen_String& s, const char* c) {
  CoolGen_String temp(s);                       // temporary copy of s
  temp += c;                                    // mutate temp with += c
  return temp;                                  // return new copy by value
}


// operator+= -- Concatenation of another CoolGen_String: x += y;
// Input:        CoolGen_String reference
// Output:       CoolGen_String object concatenated with CoolGen_String contents

inline CoolGen_String& CoolGen_String::operator+= (const CoolGen_String& s) {
  return (strcat (*this, s));                   
}

// operator+ -- String concatenation of another string: z = x + y;
// Input:       CoolGen_String reference
// Output:      CoolGen_String object concatenated with String contents

inline CoolGen_String operator+ (const CoolGen_String& s1, const CoolGen_String& s2) {
  CoolGen_String temp(s1);                      // temporary copy of s1
  temp += s2;                                   // mutate temp with += s2
  return temp;                                  // return new copy by value
}



// operator== -- Test for equality of two CoolGen_String objects
// Input:        this*, CoolGen_String reference
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator== (const CoolGen_String& s) const{
  return (is_equal (this->str, s.str, SENSITIVE));
}


// operator== -- Test for equality of an CoolGen_String and char*
// Input:        this*, char* pointer
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator== (const char* c) const {
  return (is_equal (this->str, c, SENSITIVE));
}


// operator!= -- Test for inequality of two CoolGen_String objects
// Input:        this*, CoolGen_String reference
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator!= (const CoolGen_String& s) const {
  return (is_not_equal (this->str, s.str, SENSITIVE));
}


// operator!= -- Test for inequality of two CoolGen_String objects
// Input:        this*, char* pointer
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator!= (const char* c) const {
  return (is_not_equal (this->str, c, SENSITIVE));
}


// operator< -- Test for lexical ordering before a CoolGen_String
// Input:       this*, CoolGen_String reference
// Output:      Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator< (const CoolGen_String& s) const {
  return (is_lt (this->str, s.str, SENSITIVE));
}


// operator< -- Test for lexical ordering before a CoolGen_String
// Input:       this*, char* pointer
// Output:      Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator< (const char* c) const {
  return (is_lt (this->str, c, SENSITIVE));
}


// operator> -- Test for lexical ordering after a CoolGen_String
// Input:       this*, CoolGen_String reference
// Output:      Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator> (const CoolGen_String& s) const {
  return (is_gt (this->str, s.str, SENSITIVE));
}


// operator> -- Test for lexical ordering after a CoolGen_String
// Input:       this*, char* pointer
// Output:      Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator> (const char* c) const {
  return (is_gt (this->str, c, SENSITIVE));
}


// operator<= -- Test for lexical ordering before or equal to a CoolGen_String
// Input:        this*, CoolGen_String reference
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator<= (const CoolGen_String& s) const {
  return (is_le (this->str, s.str, SENSITIVE));
}


// operator<= -- Test for lexical ordering before or equal to a CoolGen_String
// Input:        this*, char* pointer
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator<= (const char* c) const {
  return (is_le (this->str, c, SENSITIVE));
}


// operator>= -- Test for lexical ordering after or equal to a CoolGen_String
// Input:        this*, String reference
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator>= (const CoolGen_String& s) const {
  return (is_ge (this->str, s.str, SENSITIVE));
}


// operator>= -- Test for lexical ordering after or equal to a CoolGen_String
// Input:        this*, char* pointer
// Output:       Boolean TRUE/FALSE

inline Boolean CoolGen_String::operator>= (const char* c) const {
  return (is_ge (this->str, c, SENSITIVE));
}




// strlen -- Return the number of characters in the string
// Input:    CoolGen_String reference
// Output:   Length of the string

inline long strlen (const CoolGen_String& s) {
  return (s.length);
}


// atof -- Equivalent to strtod (str, (char**)END_OF_STRING)
// Input:  Reference to CoolGen_String object
// Output: Double representing value contained in string

inline double atof (const CoolGen_String& s) {
  return (strtod ((char *)s.str, (char **) END_OF_STRING));
}


// strncpy -- Returns s, with the first length characters of source copied
//            into it.  The old value of s is lost.
// Input   -- A reference to a CoolGen_String s, a char* source, and an int length.
// Output  -- The modified CoolGen_String s.

inline CoolGen_String& strncpy(CoolGen_String& s, const char* source, int n) {
  return strncpy(s, source, (long) n);
}


#endif                                          // End of GEN_STRINGH


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?