📄 sstr_04.cc
字号:
// file: $isip/class/system/SysString/sstr_04.cc// version: $Id: sstr_04.cc,v 1.9 2002/11/05 04:07:20 parihar Exp $//// isip include files//#include "SysString.h"// method: toUpper//// arguments: none//// return: a boolean value indicating status//// this method converts all characters to uppercase//boolean SysString::toUpper() { // create a temporary SysChar object // SysChar c; // loop over the elements and change to upper // for (long i = 0; i < length(); i++) { c.assign(value_d[i]); c.toUpper(); value_d[i] = c; } // exit gracefully // return true;}// method: toLower//// arguments: none//// return: a boolean value indicating status//// this method converts all characters to lowercase//boolean SysString::toLower() { // create a temporary SysChar object // SysChar c; // loop over the elements and change to lower // for (long i = 0; i < length(); i++) { c.assign(value_d[i]); c.toLower(); value_d[i] = c; } // exit gracefully // return true;}// method: toMixed//// arguments: none//// return: a boolean value indicating status//// this method converts all initial characters to lowercase. initial// characters are defined as (1) the first non-whitespace character in// the string, and (2) the first non-whitespace character following// each whitespace character in the string//boolean SysString::toMixed() { // create a temporary SysChar object // SysChar c; // find the first non-space character within the object // long i = firstNotSpace(); while (i != Integral::NO_POS) { c.assign(value_d[i]); c.toUpper(); value_d[i] = c; // jump to the next whitespace // i = firstSpace(i); // if there is whitespace, there may be a character following whitespace // if (i != Integral::NO_POS) { i = firstNotSpace(i); } } // exit gracefully // return true;}// method: toMixed//// arguments:// const SysString& sep_chrs: (input) separation characters//// return: a boolean value indicating status//// this method converts all initial characters to lowercase. initial// characters are defined as (1) the first character not in sep_chrs// in the string, and (2) the first character not in sep_chrs// following each character in sep_chrs in the string.//boolean SysString::toMixed(const SysString& sep_chrs_a) { // create a temporary SysChar object // SysChar c; // find the first instance of a character in chrs_a within the // object // long i = firstNotChr(sep_chrs_a); while (i != Integral::NO_POS) { c.assign(value_d[i]); c.toUpper(); value_d[i] = c; // jump to the next character within sep_chrs // i = firstChr(sep_chrs_a, i); // if there is a character in sep_chrs, there may be a character // following which isn't // if (i != Integral::NO_POS) { i = firstNotChr(sep_chrs_a, i); } } // exit gracefully // return true;}// method: compare//// arguments:// const unichar* arg: (input) input string//// return: long comparison result//// this method checks if the string is greater than, less than,// or equal to the object//Integral::COMPARE SysString::compare(const unichar* arg_a) const { // declare a static string // static SysString temp; // copy the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return compare(*this, temp);}// method: compare//// arguments:// const SysString& arg1: (input) input string// const SysString& arg2: (input) input string//// return: long comparison result//// this method checks if arg1 is greater than, less than, or equal to arg2//Integral::COMPARE SysString::compare(const SysString& arg1_a, const SysString& arg2_a) const { // call wcscmp function to compare // long cmp = isip_wcscmp(arg1_a.value_d, arg2_a.value_d); // branch on the return value of wcscmp // if (cmp > 0) { return Integral::GREATER; } else if (cmp < 0) { return Integral::LESSER; } // exit gracefully // return Integral::EQUAL;}// method: eq//// arguments:// const unichar* arg: (input) input string// boolean case_sensitive: (input) if the comparison is case sensitive//// return: a boolean value indicating status//// this method checks if the string is equal to the object//boolean SysString::eq(const unichar* arg_a, boolean case_sensitive_a) const { // declare a static string // static SysString temp; // copy the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return eq(temp, case_sensitive_a);}// method: eq//// arguments:// const SysString& arg: (input) input string// boolean case_sensitive: (input) if the comparison is case sensitive//// return: a boolean value indicating status//// this method checks if the string is equal to the object//boolean SysString::eq(const SysString& arg_a, boolean case_sensitive_a) const { // branch on boolean case sensitive flag // if (case_sensitive_a) { if (compare(arg_a) == Integral::EQUAL) { return true; } } // not case sensitive // else { static SysString cmp_str; static SysString this_str; // preserve the case of the input string // cmp_str.assign(arg_a); this_str.assign(*this); // change both to upper case // cmp_str.toLower(); this_str.toLower(); if (this_str.compare(cmp_str) == Integral::EQUAL) { return true; } } // exit gracefully // return false;}// method: gt//// arguments:// const unichar* arg: (input) input string//// return: a boolean value indicating status//// this method checks if the string is greater than the object//boolean SysString::gt(const unichar* arg_a) const { // declare a static string // static SysString temp; // copy the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return gt(temp);}// method: lt//// arguments:// const unichar* arg: (input) input string//// return: a boolean value indicating status//// this method checks if the string is less than the object//boolean SysString::lt(const unichar* arg_a) const { // declare a static string // static SysString temp; // copy the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return lt(temp);}// method: ne//// arguments:// const unichar* arg: (input) input string// boolean case_sensitive: (input) if the comparison is case sensitive//// return: a boolean value indicating status//// this method checks if the string is not equal to the object//boolean SysString::ne(const unichar* arg_a, boolean case_sensitive_a) const { // declare a static string // static SysString temp; // copy the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return ne(temp, case_sensitive_a);}// method: le//// arguments:// const unichar* arg: (input) input string//// return: a boolean value indicating status//// this method checks if the string is less than or equal to the object//boolean SysString::le(const unichar* arg_a) const { // declare a static string // static SysString temp; // copy the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return le(temp);}// method: ge//// arguments:// const unichar* arg: (input) input string//// return: a boolean value indicating status//// this method checks if the string is greater than or equal to the object//boolean SysString::ge(const unichar* arg_a) const { // declare static string // static SysString temp; // assign the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return ge(temp);}// method: comparePartial//// arguments:// const unichar* arg: (input) input string// long arg_offset: (input) starting position in "arg"// long num_elements: (input) number of elements to compare// long offset: (input) starting position in "this"//// return: long comparison result//// this method checks if a portion of this string greater than, less than,// or equal to the object//Integral::COMPARE SysString::comparePartial(const unichar* arg_a, long arg_offset_a, long num_elements_a, long offset_a) const { // declare local variables // static SysString temp; // assign the input buffer to a temporary string // temp.assign(arg_a); // call the master function // return comparePartial(temp, arg_offset_a, num_elements_a, offset_a);}// method: comparePartial//// arguments:// const SysString& arg: (input) input string// long arg_offset: (input) starting position in "arg"// long num_elements: (input) number of elements to compare// long offset: (input) starting position in "this"//// return: long comparison result//// this method checks if a portion of this string greater than, less// than, or equal to the object//Integral::COMPARE SysString::comparePartial(const SysString& arg_a, long arg_offset_a, long num_elements_a, long offset_a) const { // check if the source offset is greater than the length of the // current string // if (arg_offset_a > length()) { // check if the destination offset is greater than the length of // the input string // if (offset_a > arg_a.length()) { return Integral::EQUAL; } else { return Integral::GREATER; } } else if (offset_a > arg_a.length()) { return Integral::LESSER; } // check the number of elements // if (num_elements_a < 1) { Error::handle(name(), L"comparePartial", Error::ARG, __FILE__, __LINE__); return Integral::EQUAL; } // call isip_wcsncmp to get comparison result // long cmp = isip_wcsncmp(&value_d[arg_offset_a], &(arg_a.value_d[offset_a]), num_elements_a); if (cmp > 0) { return Integral::GREATER; } else if (cmp < 0) { return Integral::LESSER; } // exit gracefully // return Integral::EQUAL;}// method: firstStr//// arguments:// const SysString& str: (output) the substring// long start: (input) where to start looking//// return: long index within the string//// this method finds the first instance of str_a within the object//long SysString::firstStr(const SysString& str_a, long start_a) const { // check the arguments // if (start_a > length()) { return Integral::NO_POS; } if (start_a == Integral::NO_POS) { start_a = 0; } // find the string // unichar* index = isip_wcsstr(&value_d[start_a], str_a.value_d); if (index == (unichar*)NULL) { return Integral::NO_POS; } // return the position // return (((long)index - (long)value_d) / sizeof(unichar));}// method: lastStr//// arguments:// const SysString& str: (output) the substring// long end: (input) where to start looking//// return: long index within the string//// this method finds the last instance of str_a within the object//long SysString::lastStr(const SysString& str_a, long end_a) const { // length can't be less than or equal to zero // if (length() < 1) { return Integral::NO_POS; } // check the arguments // if ((end_a == Integral::NO_POS) || end_a >= length()) { if (eq(str_a)) { return 0; } end_a = length() - 1; } if (str_a.length() >= end_a) { return Integral::NO_POS; } // we need a temporary placeholder // unichar c = value_d[end_a + 1]; value_d[end_a + 1] = (unichar)NULL; // loop over the elements of string
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -