strings.pp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. Strings unit for PChar (asciiz/C compatible strings) handling
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit strings;
  13. {$S-}
  14. interface
  15. { Returns the length of a string }
  16. function strlen(p : pchar) : longint;
  17. { Converts a Pascal string to a null-terminated string }
  18. function strpcopy(d : pchar;const s : string) : pchar;
  19. { Converts a null-terminated string to a Pascal string }
  20. function strpas(p : pchar) : string;
  21. { Copies source to dest, returns a pointer to dest }
  22. function strcopy(dest,source : pchar) : pchar;
  23. { Copies at most maxlen bytes from source to dest. }
  24. { Returns a pointer to dest }
  25. function strlcopy(dest,source : pchar;maxlen : longint) : pchar;
  26. { Copies source to dest and returns a pointer to the terminating }
  27. { null character. }
  28. function strecopy(dest,source : pchar) : pchar;
  29. { Returns a pointer tro the terminating null character of p }
  30. function strend(p : pchar) : pchar;
  31. { Appends source to dest, returns a pointer do dest}
  32. function strcat(dest,source : pchar) : pchar;
  33. { Compares str1 und str2, returns }
  34. { a value <0 if str1<str2; }
  35. { 0 when str1=str2 }
  36. { and a value >0 if str1>str2 }
  37. function strcomp(str1,str2 : pchar) : longint;
  38. { The same as strcomp, but at most l characters are compared }
  39. function strlcomp(str1,str2 : pchar;l : longint) : longint;
  40. { The same as strcomp but case insensitive }
  41. function stricomp(str1,str2 : pchar) : longint;
  42. { Copies l characters from source to dest, returns dest. }
  43. function strmove(dest,source : pchar;l : longint) : pchar;
  44. { Appends at most l characters from source to dest }
  45. function strlcat(dest,source : pchar;l : longint) : pchar;
  46. { Returns a pointer to the first occurrence of c in p }
  47. { If c doesn't occur, nil is returned }
  48. function strscan(p : pchar;c : char) : pchar;
  49. { Returns a pointer to the last occurrence of c in p }
  50. { If c doesn't occur, nil is returned }
  51. function strrscan(p : pchar;c : char) : pchar;
  52. { converts p to all-lowercase, returns p }
  53. function strlower(p : pchar) : pchar;
  54. { converts p to all-uppercase, returns p }
  55. function strupper(p : pchar) : pchar;
  56. { The same al stricomp, but at most l characters are compared }
  57. function strlicomp(str1,str2 : pchar;l : longint) : longint;
  58. { Returns a pointer to the first occurrence of str2 in }
  59. { str2 Otherwise returns nil }
  60. function strpos(str1,str2 : pchar) : pchar;
  61. { Makes a copy of p on the heap, and returns a pointer to this copy }
  62. function strnew(p : pchar) : pchar;
  63. { Allocates L bytes on the heap, returns a pchar pointer to it }
  64. function stralloc(L : longint) : pchar;
  65. { Releases a null-terminated string from the heap }
  66. procedure strdispose(p : pchar);
  67. implementation
  68. { Read Processor dependent part, shared with sysutils unit }
  69. {$i strings.inc }
  70. { Read processor denpendent part, NOT shared with sysutils unit }
  71. {$i stringss.inc }
  72. { Read generic string functions that are not implemented for the processor }
  73. {$i genstr.inc}
  74. {$i genstrs.inc}
  75. { Functions not in assembler, but shared with sysutils unit }
  76. {$i stringsi.inc}
  77. { Functions, different from the one in sysutils }
  78. function stralloc(L : longint) : pchar;
  79. begin
  80. StrAlloc:=Nil;
  81. GetMem (Stralloc,l);
  82. end;
  83. function strnew(p : pchar) : pchar;
  84. var
  85. len : longint;
  86. begin
  87. strnew:=nil;
  88. if (p=nil) or (p^=#0) then
  89. exit;
  90. len:=strlen(p)+1;
  91. getmem(strnew,len);
  92. if strnew<>nil then
  93. strmove(strnew,p,len);
  94. end;
  95. procedure strdispose(p : pchar);
  96. begin
  97. if p<>nil then
  98. begin
  99. freemem(p);
  100. p:=nil;
  101. end;
  102. end;
  103. end.
  104. {
  105. $Log$
  106. Revision 1.5 2003-07-07 20:22:05 peter
  107. * generic string routines added
  108. Revision 1.4 2002/09/07 15:07:46 peter
  109. * old logs removed and tabs fixed
  110. }