strings.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 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. interface
  14. { Returns the length of a string }
  15. function strlen(p : pchar) : longint;
  16. { Converts a Pascal string to a null-terminated string }
  17. function strpcopy(d : pchar;const s : string) : pchar;
  18. { Converts a null-terminated string to a Pascal string }
  19. function strpas(p : pchar) : string;
  20. { Copies source to dest, returns a pointer to dest }
  21. function strcopy(dest,source : pchar) : pchar;
  22. { Copies at most maxlen bytes from source to dest. }
  23. { Returns a pointer to dest }
  24. function strlcopy(dest,source : pchar;maxlen : longint) : pchar;
  25. { Copies source to dest and returns a pointer to the terminating }
  26. { null character. }
  27. function strecopy(dest,source : pchar) : pchar;
  28. { Returns a pointer tro the terminating null character of p }
  29. function strend(p : pchar) : pchar;
  30. { Appends source to dest, returns a pointer do dest}
  31. function strcat(dest,source : pchar) : pchar;
  32. { Compares str1 und str2, returns }
  33. { a value <0 if str1<str2; }
  34. { 0 when str1=str2 }
  35. { and a value >0 if str1>str2 }
  36. function strcomp(str1,str2 : pchar) : longint;
  37. { The same as strcomp, but at most l characters are compared }
  38. function strlcomp(str1,str2 : pchar;l : longint) : longint;
  39. { The same as strcomp but case insensitive }
  40. function stricomp(str1,str2 : pchar) : longint;
  41. { Copies l characters from source to dest, returns dest. }
  42. function strmove(dest,source : pchar;l : longint) : pchar;
  43. { Appends at most l characters from source to dest }
  44. function strlcat(dest,source : pchar;l : longint) : pchar;
  45. { Returns a pointer to the first occurrence of c in p }
  46. { If c doesn't occur, nil is returned }
  47. function strscan(p : pchar;c : char) : pchar;
  48. { Returns a pointer to the last occurrence of c in p }
  49. { If c doesn't occur, nil is returned }
  50. function strrscan(p : pchar;c : char) : pchar;
  51. { converts p to all-lowercase, returns p }
  52. function strlower(p : pchar) : pchar;
  53. { converts p to all-uppercase, returns p }
  54. function strupper(p : pchar) : pchar;
  55. { The same al stricomp, but at most l characters are compared }
  56. function strlicomp(str1,str2 : pchar;l : longint) : longint;
  57. { Returns a pointer to the first occurrence of str2 in }
  58. { str2 Otherwise returns nil }
  59. function strpos(str1,str2 : pchar) : pchar;
  60. { Makes a copy of p on the heap, and returns a pointer to this copy }
  61. function strnew(p : pchar) : pchar;
  62. { Allocates L bytes on the heap, returns a pchar pointer to it }
  63. function stralloc(L : longint) : pchar;
  64. { Releases a null-terminated string from the heap }
  65. procedure strdispose(p : pchar);
  66. implementation
  67. { Read Processor dependent part, shared with sysutils unit }
  68. {$i strings.inc }
  69. { Read processor denpendent part, NOT shared with sysutils unit }
  70. {$i stringss.inc }
  71. { Functions not in assembler, but shared with sysutils unit }
  72. {$i stringsi.inc}
  73. { Functions, different from the one in sysutils }
  74. procedure strdispose(p : pchar);
  75. begin
  76. if p<>nil then
  77. freemem(p,strlen(p)+1);
  78. end;
  79. function stralloc(L : longint) : pchar;
  80. begin
  81. StrAlloc:=Nil;
  82. GetMem (Stralloc,l);
  83. end;
  84. end.
  85. {
  86. $Log$
  87. Revision 1.1 1999-02-25 07:42:03 michael
  88. * Joined strings and sysutils
  89. Revision 1.7 1998/08/05 08:59:53 michael
  90. reverted to non-assmebler version, florians fix is applied.
  91. Revision 1.4 1998/05/31 14:15:52 peter
  92. * force to use ATT or direct parsing
  93. Revision 1.3 1998/05/30 14:30:22 peter
  94. * force att reading
  95. Revision 1.2 1998/05/23 01:14:06 peter
  96. + I386_ATT switch
  97. }