⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.h

📁 eC++编译器源码
💻 H
字号:
#pragma String

  const unsigned int
   first=0, /* Use String.first to insert or manipulate the beginning
                    of a string */
   last = 0xFFFF;/* Use String.last to insert after or manipulate the end. */

/* A string is indexed from left to right, 0..HIGH(s).  The null character ""
   or 0C terminates a string. Note: unsigned int names with the suffix CS are
   intended to be used with constant strings.
*/

  unsigned int Length(char &s[]);
  /* This unsigned int Length takes an input array, "s", and returns the    */
  /* length of "s".  It will return a number from 0..65K, the            */
  /* maximum array size.                                                */
  
  unsigned int Occurs(char &left[], char &right[]);
  /* This unsigned int Occurs takes two input arrays, "left" and "right"    */
  /* and determines if "right" is a substring of "left".  If so, the     */
  /* starting position where "right" begins in "left" is returned.  This */
  /* may be 0..HIGH(left).  If, however, "right" is not a substring of   */
  /* "left", the number String.last is returned.                         */

  unsigned int OccursCS(char &left[], char right[]);
  /* This unsigned int OccursCS performs the same function as Occurs; it    */
  /* simply performs unsigned int Occurs.                                   */

  void Insert(char &s[], char &w[], unsigned int at);
  /* This unsigned int Insert takes two input arrays, "s" and "w" and a     */
  /* positive number, "at"; it modifies "s" so "w" is inserted at        */
  /* position "at".  All remaining characters in "s" are moved right.    */
  /* If "at" is the position of the null character for end of string,    */
  /* then the two strings are simply concatenated.  If "at" is greater   */
  /* than the length of "s", then an error is reported.  Also, if a      */
  /* string to be inserted, "w", cannot fit in the array size, an error  */
  /* is reported.                                                        */

  void InsertCS(char &s[], unsigned int at, char w[]);
  /* This unsigned int InsertCS performs the same function as Insert; Note  */
  /* the change in parameter order.  This unsigned int performs unsigned int   */
  /* Insert.                                                             */

  void Delete(char &s[], unsigned int at, unsigned int N);
  /* This unsigned int Delete takes an input array of characters, "s" and  */
  /* two cardinal numbers, "at" and "N" and deletes "N" characters       */
  /* beginning with position "at" - 1.  The unsigned int deletes characters */
  /* from right to left.  "N" must be greater than 0, and must not       */
  /* extend past the leftmost character or errors will be reported.      */
  /* "At" - 1 must also be a valid position in the string or an error    */
  /* will be reported.                                                   */

  void Copy(char &dest[], char &source[]);
  /* This unsigned int Copy takes an input array "dest" and overwrites it   */
  /* with input array "source".  "Source" and "dest" may be differing    */
  /* lengths; "dest", upon completion will have the value of "source".   */
  /* The unsigned int will insert the null character to terminate the       */
  /* string if necessary.                                                */

  void CopyCS(char &dest[], char source[]);
  /* This unsigned int CopyCS performs the same function as Copy; it        */
  /* performs unsigned int Copy.                                            */

  int Compare(char &left[], char &right[]);
  /* This unsigned int Compare takes two input character arrays, "left"     */
  /* and "right" and compares them.  If all characters are the same,     */
  /* 0 is returned.  Position numbers begin with 1 as the leftmost       */
  /* character.  If the strings differ, the position number is returned  */
  /* of the first differing position.  If the position number returned   */
  /* is negative, the character in "right" that differs is less than     */
  /* the character in "left".  Example:  "left" = ijl; "right" = ijm;    */
  /* result is -3 and ABS(result) is the position of difference.         */

  int CompareCS(char &left[], char right[]);
  /* This unsigned int CompareCS performs the same function as Compare; it  */
  /* does this simply by performing Compare.                             */

  void Fill(char &dest[], char &fill[], unsigned int at, unsigned int N);
  /* This unsigned int Fill takes as input two character arrays, "dest" and */
  /* "fill" and two cardinal numbers, "at" and "N"; it fills the string  */
  /* "dest" beginning at position "at" for "N" characters with the       */
  /* pattern "fill".  If "N" is greater than the length of "fill", then  */
  /* "fill" is repeated up to "N" characters.  If "N" is less than the   */
  /* length of "fill", then only the first "N" characters of "fill" are  */
  /* put in "dest".  If "N" is 0, the string is filled up to the null    */
  /* string terminator.  If "at" is greater than the length of "dest",   */
  /* "dest" remains unaffected.                                          */  
  /* Example:  "dest" = catfish; "fill" = soup; "at" = 3; "N" = 4;       */
  /* result is:  catsoup.                                                */
  /* Example:  "dest" = abcdef;  "fill" = words; "at" = 0; "N" = 6;      */
  /* result is:  wordsw.                                                 */

  void FillCS(char &dest[], char fill[], unsigned int at, unsigned int N);
  /* This unsigned int FillCS performs the same function as Fill; it        */
  /* does this simply by performing Fill.                                */

/* rationale:

 - same representation as compiler used: allows compiler generated
   assignment with constant strings (eg. also the empty string "" )
   it is possible to add further user operators since the structure 
   of the strings are known. efficient indexing.

 - this is a minimal set of operators, 

   need                    tool
   ====                    ====
   assignment:             Copy or the := statement
   copying parts:          Copy
   making strings longer:  Insert, InsertCh
   making strings shorter: Delete
   substring search:       Occurs
   compare:                Compare
   access of a character:  array indexing

###################################################################################
unsigned int:  Length
                         Input Parameters               Expected Result
                               s
----------------------------------------------------------------------------------
1)  value:                    "a"                              1
2)  value:                    "any"                            3
3)  value:                    "abcdefghij"                     10
4)  value:                    "123456789012345678901"          21
5)  value:                    "1234567890123456789012323"      21


###################################################################################
unsigned int:  Occurs and OccursCS
                         Input Parameters               Expected Result
                         left       right
-----------------------------------------------------------------------------------
1)  value:                 "a"       "a"                      0
2)  value:                 "a"       "b"                      String.last
3)  value:                 "abc"     "a"                      0
4)  value:                 "abc"     "abc"                    0
5)  value:                 "xabc"    "abc"                    1
6)  value:                 "xabc"    "b"                      2
7)  value:                 "abc"     "c"                      2
8)  value:             "abcdefghijk" "jk"                     9
9)  value:                 "cab"     "can"                    String.last
10) value:   "12345678901234567890z" "z"                      20


###################################################################################
unsigned int:  Insert and InsertCS
                         Input Parameters            Expected Result
                     s               w         at
-----------------------------------------------------------------------------------
1)  value:                 "a"       "b"        0   "ba"
2)  value:                 "a"       "b"        1   "ab"
3)  value:        "longstring"  "rather"        0   "ratherlongstring"
4)  value:            "sample"  "string"        6   "samplestring"
5)  value:             "putin"  "middle"        3   "putmiddlein"
6)  value:         "mindytest"       "z"        5   "mindyztest"
7)  value:           "another"    "test"        7   "anothertest"
8)  value:       "inthemiddle" "addthis"        5   "intheaddthismiddle"
9)  value:           "atstart" "addthis"        0   "addthisatstart"
10) value:       "inthemiddle" "addthis"        11  "inthemiddleaddthis"
11) value:             "atend" "addthis"        5   "atendaddthis"
12) value:                 "1"  "234567"        1   "1234567"
13) value:            "234567"       "1"        0   "1234567"
14) value:            "addone"       "c"        3   "addcone"
15) value:            "addone"       "s"        5   "addonse"
16) value:               "add"       "s"        4   Error: At too big
17) value:  "1234567890123456789" "1234"        10  Error: Size too big







###################################################################################
unsigned int:  Delete
                         Input Parameters               Expected Result
                     s               at             N
-----------------------------------------------------------------------------------
1)  value:              "sample"       6             6   ""
2)  value:           "chopstick"       9             5   "chop" 
3)  value:	             "a"       1	     1	 ""     
4)  value:            "chopstick"      4    	     4   "stick"
5)  value:     	      "chopstick"      1	     1   "hopstick"
6)  value:                 "abcd"      4	     1   "abc"     			
7)  value:	           "abcd"      4  	     2   "ab"     
8)  value:   		   "abcd"      4             3   "a"  
9)  value:   	     "sampleword"      10            4   "sample"  
10) value:               "sample"      5             0   "sample"
11) value:	         "sample"      7       	     2   Error:  Invalid "at"
12) value:               "sample"      1    	     3   Error:  Invalid "at"
13) value:"123456789012345678901"      21            20  "1"
14) value:                    "a"      0             1   Error:  Invalid "at"   
15) value:"123456789012345678901"      21            21  ""    
16) value:                  "cab"      2             4   Error:  Invalid "N"


###################################################################################
unsigned int:  Copy and CopyCS
                         Input Parameters               Expected Result
                       dest        source       
-----------------------------------------------------------------------------------
1)  value:               "a"                     "b"    "b"
2)  value:             "bat"                     "c"    "c"
3)  value:      "longstring"          "longerstring"    "longerstring"
4)  value:      "samelength"            "alsolength"    "alsolength"
5)  value:              "ab"                     "a"    "a"
6)  value: "123456789012345678901"                "z"   "z"
7)  value:"1234567890123456789012"                "z"   "z"
8)  value:  "12345678901234567890"                "z"   "z"
9)  value:               "z"    "123456789012345678901" "123456789012345678901"


###################################################################################
unsigned int:  Compare and CompareCS
                         Input Parameters               Expected Result
                       left                  right
-----------------------------------------------------------------------------------
1)  value:               "a"                       "a"         0
2)  value:             "long"                   "long"         0
3)  value:               "ab"                    "abc"        -3
4)  value:              "abc"                     "ab"         3
5)  value:            "ijklm"                  "ijkln"        -5
6)  value:                "a"                      "b"        -1
7)  value:              "and"                    "amn"         2
8)  value: "particularlylong"      "particularlyshort"       -13                 
9)  value:           "longer"                "shorter"        -1
10) value: "123456789012345678901" "123456789012345678901"     0
11) value: "123456789012345678901" "12345678901234567890z"   -21
12) value: "12345678901234567890z" "123456789012345678901"    21











#################################################################################
unsigned int:  Fill and FillCS
                         Input Parameters               Expected Result
                        dest             fill          at       N
---------------------------------------------------------------------------------
1)  value:             "whole"          "thing"       0  5 "thing"   
2)  value:	           "a"              "b"       0  0 "b"
3)  value:		   "a"             "bc"       0  2 "bc"
4)  value:          "inmiddle"            "the"       3  4 "inmthete"
5)  value:           "longone"              "z"       0  0 "zzzzzzz"
6)  value:	     "longone"              "z"       2  0 "lozzzzz"
7)  value:	     "longone"              "z"       6  0 "longonz"
8)  value:            "abcdef"            "rep"       0  0 "reprep"
9)  value:	      "abcdef"            "rep"       2  0 "abrepr"
10) value:            "abcdef"            "rep"       5  0 "abcder"
11) value:            "abcdef"            "rep"	      6  0 "abcdef"
12) value:       "abcdefghijk"           "many"	      0  2 "macdefghijk"
13) value:       "abcdefghijk"           "many"	      7  3 "abcdefgmank"
14) value:       "abcdefghijk"           "many"       0  6 "manymaghijk"
15) value:                 "a"             "ab"       0	10 "ababababab"
16) value:                 "u"             "uv"       1  4 "uuvuv"
17) value: "012345678901234567890"         "f"       20  1 "01234567890123456789f"
18) value:          "z"      "012345678901234567890" 20 20 "z"
19) value:          "z"      "012345678901234567890"  0 20 "012345678901234567890"
20) value:          "z"     "0123456789012345678901"  0 20 "012345678901234567890"
21) value:          "z"                    "f"        2  5 "z"


Note:  If "at" is greater than the length of "dest", "dest" remains the same,
       as in case 21).  This could be flagged as an error to remain consistent 
       with the Insert and InsertCS unsigned ints.

###################################################################################################################
*/

⌨️ 快捷键说明

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