string.h
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 505 行 · 第 1/2 页
H
505 行
#if ERROR_CHECKING
if (ratio <= 0.0) // If negative growth factor
this->ratio_error (ratio); // Raise exception
#endif
this->growth_ratio = ratio; // Set growth size
}
// operator const char* -- Provide an accessor to the String character pointer
// Input: this* CoolString pointer
// Output: this->str character pointer
inline CoolString::operator const char*() const {return this->str;}
// operator= -- CoolString assignment to a single character: x = 'A';
// Input: Single character
// Output: CoolString object containing character string
inline CoolString& CoolString::operator= (char c) {
return (strcpy (*this, c));
}
// operator= -- CoolString assignment to a character string: x = "ABCDEFG";
// Input: Character string
// Output: CoolString object containing character string
inline CoolString& CoolString::operator= (const char* c) {
return (strcpy (*this, c));
}
// operator= -- CoolString assignment to another CoolString: x = y;
// Input: Reference to CoolString object
// Output: CoolString object sharing memory with other CoolString
inline CoolString& CoolString::operator= (const CoolString& s) {
return (strcpy (*this, s));
}
// operator= -- Assignment from an envelope back to real string
// Input: envelope reference
// Output: string reference with contents in envelope being swapped over
inline CoolString& CoolString::operator= (CoolStringE& env){
env.shallow_swap((CoolStringE*)this, &env); // same physical layout
return *this;
}
// operator+= -- CoolString concatenation of a character: x += 'A';
// Input: Character
// Output: CoolString object concatenated with character
inline CoolString& CoolString::operator+= (char c) {
return (strcat (*this, c));
}
// operator+ -- CoolString concatenation of a character: x = x + 'A';
// Input: Character
// Output: new CoolString object concatenated with character
inline CoolStringE CoolString::operator+ (char c) const {
CoolString temp(*this); // Temporary string
temp += c; // Concatenate temp with c
CoolStringE& result = (CoolStringE&) temp; // same physical object
return result; // copy of envelope
}
// operator+= -- CoolString concatenation of a character string: x += "ABCDEFG";
// Input: Character CoolString
// Output: CoolString object concatenated with character CoolString
inline CoolString& CoolString::operator+= (const char* c) {
return (strcat (*this, c));
}
// operator+ -- CoolString concatenation of a character string: x = x + "ABCDEFG";
// Input: Character string
// Output: CoolString object concatenated with character string
inline CoolStringE CoolString::operator+ (const char* c) const {
CoolString temp(*this); // Temporary string
temp += c; // Concatenate temp with c
CoolStringE& result = (CoolStringE&) temp; // same physical object
return result; // copy of envelope
}
// operator+= -- CoolString concatenation of another string: x += y;
// Input: CoolString reference
// Output: CoolString object concatenated with CoolString contents
inline CoolString& CoolString::operator+= (const CoolString& s) {
return (strcat (*this, s));
}
// operator+ -- CoolString concatenation of another string: x = x + y;
// Implemented as a friend function in CoolEnvelope
// Input: CoolString reference
// Output: CoolString object concatenated with CoolString contents
// CoolString CoolString::operator+ (const CoolString& s) const {
// CoolString temp(*this); // Temporary string
// strcat(temp, s); // Concatenate temp with s
// return temp; // Return by value
// }
// operator== -- Test for equality of two CoolString objects
// Input: this* CoolString pointer, CoolString reference
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator== (const CoolString& s) const {
return (is_equal (*this, s.str, SENSITIVE));
}
// operator== -- Test for equality of a CoolString and char*
// Input: this* CoolString pointer, char* pointer
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator== (const char* c) const {
return (is_equal (*this, c, SENSITIVE));
}
// operator!= -- Test for inequality of two CoolString objects
// Input: this* CoolString pointer, CoolString reference
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator!= (const CoolString& s) const {
return (is_not_equal (*this, s.str, SENSITIVE));
}
// operator!= -- Test for inequality of two CoolString objects
// Input: this* CoolString pointer, char* pointer
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator!= (const char* c) const {
return (is_not_equal (*this, c, SENSITIVE));
}
// operator< -- Test for lexical ordering before a CoolString
// Input: this* CoolString pointer, CoolString reference
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator< (const CoolString& s) const {
return (is_lt (*this, s.str, SENSITIVE));
}
// operator< -- Test for lexical ordering before a CoolString
// Input: this* CoolString pointer, char* pointer
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator< (const char* c) const {
return (is_lt (*this, c, SENSITIVE));
}
// operator> -- Test for lexical ordering after a CoolString
// Input: this* CoolString pointer, CoolString reference
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator> (const CoolString& s) const {
return (is_gt (*this, s.str, SENSITIVE));
}
// operator> -- Test for lexical ordering after a CoolString
// Input: this* CoolString pointer, char* pointer
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator> (const char* c) const {
return (is_gt (*this, c, SENSITIVE));
}
// operator<= -- Test for lexical ordering before or equal to a CoolString
// Input: this* CoolString pointer, CoolString reference
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator<= (const CoolString& s) const {
return (is_le (*this, s.str, SENSITIVE));
}
// operator<= -- Test for lexical ordering before or equal to a CoolString
// Input: this* CoolString pointer, char* pointer
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator<= (const char* c) const {
return (is_le (*this, c, SENSITIVE));
}
// operator>= -- Test for lexical ordering after or equal to a CoolString
// Input: this* CoolString pointer, CoolString reference
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator>= (const CoolString& s) const {
return (is_ge (*this, s.str, SENSITIVE));
}
// operator>= -- Test for lexical ordering after or equal to a CoolString
// Input: this* CoolString pointer, char* pointer
// Output: Boolean TRUE/FALSE
inline Boolean CoolString::operator>= (const char* c) const {
return (is_ge (*this, c, SENSITIVE));
}
// strlen -- Return the number of characters in the CoolString
// Input: CoolString reference
// Output: Length of the string
inline long strlen (const CoolString& s) {
return (s.length);
}
// atof -- Equivalent to strtod (str, (char**)END_OF_STRING)
// Input: Reference to CoolString object
// Output: Double representing value contained in CoolString
inline double atof (const CoolString& 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 CoolString s, a char* source, and an int length.
// Output -- The modified CoolString s.
inline CoolString& strncpy(CoolString& s, const char* source, int n) {
return strncpy(s, source, (long) n);
}
//## BC++ 3.1 bug
#undef CoolEnvelope
#endif // End #ifdef of STRINGH
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?