瀏覽代碼

+ Fixed typo in stralloc reported by Mark Emerson; Other cosmetic changes.

michael 22 年之前
父節點
當前提交
e9bcbe352d
共有 1 個文件被更改,包括 68 次插入97 次删除
  1. 68 97
      docs/strings.tex

+ 68 - 97
docs/strings.tex

@@ -19,16 +19,21 @@
 %   Boston, MA 02111-1307, USA. 
 %   Boston, MA 02111-1307, USA. 
 %
 %
 \chapter{The STRINGS unit.}
 \chapter{The STRINGS unit.}
+\label{ch:strings}
+\FPCexampledir{stringex}
+
 This chapter describes the \var{STRINGS} unit for \fpc. This unit is system
 This chapter describes the \var{STRINGS} unit for \fpc. This unit is system
 independent, and therefore works on all supported platforms.
 independent, and therefore works on all supported platforms.
 
 
 Since the unit only provides some procedures and functions, there is
 Since the unit only provides some procedures and functions, there is
 only one section, which gives the declarations of these functions, together
 only one section, which gives the declarations of these functions, together
 with an explanation. 
 with an explanation. 
+
 \section{Functions and procedures.}
 \section{Functions and procedures.}
+
 \begin{function}{StrAlloc}
 \begin{function}{StrAlloc}
 \Declaration
 \Declaration
-Function StrAlloc (Len : Longint);PChar
+Function StrAlloc (Len : Longint) : PChar;
 \Description
 \Description
 \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
 \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
 terminating \var{\#0} included, and returns a pointer to it.
 terminating \var{\#0} included, and returns a pointer to it.
@@ -37,26 +42,25 @@ If there is not enough memory, a run-time error occurs.
 \SeeAlso
 \SeeAlso
 \seef{StrNew}, \seef{StrPCopy}.
 \seef{StrNew}, \seef{StrPCopy}.
 \end{function}
 \end{function}
+
+
 \begin{function}{StrCat}
 \begin{function}{StrCat}
 \Declaration
 \Declaration
 Function StrCat (Dest,Source : PChar) : PChar;
 Function StrCat (Dest,Source : PChar) : PChar;
 \Description
 \Description
-
 Attaches \var{Source} to \var{Dest} and returns \var{Dest}.
 Attaches \var{Source} to \var{Dest} and returns \var{Dest}.
-
 \Errors
 \Errors
 No length checking is performed.
 No length checking is performed.
 \SeeAlso
 \SeeAlso
 \seem{Concat}{}
 \seem{Concat}{}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex11.pp}}
-\html{\input{stringex/ex11.tex}}
+
+\FPCexample{ex11}
+
 \begin{function}{StrComp}
 \begin{function}{StrComp}
 \Declaration
 \Declaration
 Function StrComp (S1,S2 : PChar) : Longint;
 Function StrComp (S1,S2 : PChar) : Longint;
-
 \Description
 \Description
-
 Compares the null-terminated strings \var{S1} and \var{S2}.
 Compares the null-terminated strings \var{S1} and \var{S2}.
 The result is 
 The result is 
 \begin{itemize}
 \begin{itemize}
@@ -64,84 +68,75 @@ The result is
 \item 0 when \var{S1=S2}.
 \item 0 when \var{S1=S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \end{itemize}
 \end{itemize}
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seef{StrLComp}, \seef{StrIComp}, \seef{StrLIComp}
 \seef{StrLComp}, \seef{StrIComp}, \seef{StrLIComp}
 \end{function}
 \end{function}
+
 For an example, see \seef{StrLComp}.
 For an example, see \seef{StrLComp}.
+
 \begin{function}{StrCopy}
 \begin{function}{StrCopy}
 \Declaration
 \Declaration
 Function StrCopy (Dest,Source : PChar) : PChar;
 Function StrCopy (Dest,Source : PChar) : PChar;
-
 \Description
 \Description
- 
 Copy the null terminated string in \var{Source} to \var{Dest}, and
 Copy the null terminated string in \var{Source} to \var{Dest}, and
 returns a pointer to \var{Dest}. \var{Dest} needs enough room to contain
 returns a pointer to \var{Dest}. \var{Dest} needs enough room to contain
 \var{Source}, i.e. \var{StrLen(Source)+1} bytes.
 \var{Source}, i.e. \var{StrLen(Source)+1} bytes.
-
 \Errors
 \Errors
 No length checking is performed.
 No length checking is performed.
 \SeeAlso
 \SeeAlso
  \seef{StrPCopy}, \seef{StrLCopy}, \seef{StrECopy}
  \seef{StrPCopy}, \seef{StrLCopy}, \seef{StrECopy}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex4.pp}}
-\html{\input{stringex/ex4.tex}}
+
+\FPCexample{ex4}
+
 \begin{procedure}{StrDispose}
 \begin{procedure}{StrDispose}
 \Declaration
 \Declaration
 Procedure StrDispose (P : PChar);
 Procedure StrDispose (P : PChar);
-
 \Description
 \Description
-
 Removes the string in \var{P} from the heap and releases the memory.
 Removes the string in \var{P} from the heap and releases the memory.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seem{Dispose}{}, \seef{StrNew}
 \seem{Dispose}{}, \seef{StrNew}
 \end{procedure}
 \end{procedure}
-\latex{\lstinputlisting{stringex/ex17.pp}}
-\html{\input{stringex/ex17.tex}}
+
+\FPCexample{ex17}
+
 \begin{function}{StrECopy}
 \begin{function}{StrECopy}
 \Declaration
 \Declaration
 Function StrECopy (Dest,Source : PChar) : PChar;
 Function StrECopy (Dest,Source : PChar) : PChar;
-
 \Description
 \Description
-
 Copies the Null-terminated string in \var{Source} to \var{Dest}, and
 Copies the Null-terminated string in \var{Source} to \var{Dest}, and
 returns a pointer to the end (i.e. the terminating Null-character) of the
 returns a pointer to the end (i.e. the terminating Null-character) of the
 copied string.
 copied string.
-
 \Errors
 \Errors
 No length checking is performed.
 No length checking is performed.
 \SeeAlso
 \SeeAlso
 \seef{StrLCopy}, \seef{StrCopy}
 \seef{StrLCopy}, \seef{StrCopy}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex6.pp}}
-\html{\input{stringex/ex6.tex}}
+
+\FPCexample{ex6}
+
 \begin{function}{StrEnd}
 \begin{function}{StrEnd}
 \Declaration
 \Declaration
 Function StrEnd (P : PChar) : PChar;
 Function StrEnd (P : PChar) : PChar;
-
 \Description
 \Description
-
 Returns a pointer to the end of \var{P}. (i.e. to the terminating
 Returns a pointer to the end of \var{P}. (i.e. to the terminating
 null-character.
 null-character.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seef{StrLen}
 \seef{StrLen}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex7.pp}}
-\html{\input{stringex/ex7.tex}}
+
+\FPCexample{ex7}
+
 \begin{function}{StrIComp}
 \begin{function}{StrIComp}
 \Declaration
 \Declaration
 Function StrIComp (S1,S2 : PChar) : Longint;
 Function StrIComp (S1,S2 : PChar) : Longint;
-
 \Description
 \Description
-
 Compares the null-terminated strings \var{S1} and \var{S2}, ignoring case.
 Compares the null-terminated strings \var{S1} and \var{S2}, ignoring case.
 The result is 
 The result is 
 \begin{itemize}
 \begin{itemize}
@@ -149,36 +144,32 @@ The result is
 \item 0 when \var{S1=S2}.
 \item 0 when \var{S1=S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \end{itemize}
 \end{itemize}
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seef{StrLComp}, \seef{StrComp}, \seef{StrLIComp}
 \seef{StrLComp}, \seef{StrComp}, \seef{StrLIComp}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex8.pp}}
-\html{\input{stringex/ex8.tex}}
+
+\FPCexample{ex8}
+
 \begin{function}{StrLCat}
 \begin{function}{StrLCat}
 \Declaration
 \Declaration
 Function StrLCat (Dest,Source : PChar; MaxLen : Longint) : PChar;
 Function StrLCat (Dest,Source : PChar; MaxLen : Longint) : PChar;
-
 \Description
 \Description
-
 Adds \var{MaxLen} characters from \var{Source} to \var{Dest}, and adds a
 Adds \var{MaxLen} characters from \var{Source} to \var{Dest}, and adds a
 terminating null-character. Returns \var{Dest}.
 terminating null-character. Returns \var{Dest}.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seef{StrCat}
 \seef{StrCat}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex12.pp}}
-\html{\input{stringex/ex12.tex}}
+
+\FPCexample{ex12}
+
 \begin{function}{StrLComp}
 \begin{function}{StrLComp}
 \Declaration
 \Declaration
 Function StrLComp (S1,S2 : PChar; L : Longint) : Longint;
 Function StrLComp (S1,S2 : PChar; L : Longint) : Longint;
-
 \Description
 \Description
-
 Compares maximum \var{L} characters of the null-terminated strings 
 Compares maximum \var{L} characters of the null-terminated strings 
 \var{S1} and \var{S2}. 
 \var{S1} and \var{S2}. 
 The result is 
 The result is 
@@ -187,52 +178,45 @@ The result is
 \item 0 when \var{S1=S2}.
 \item 0 when \var{S1=S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \end{itemize}
 \end{itemize}
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seef{StrComp}, \seef{StrIComp}, \seef{StrLIComp}
 \seef{StrComp}, \seef{StrIComp}, \seef{StrLIComp}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex8.pp}}
-\html{\input{stringex/ex8.tex}}
+
+\FPCexample{ex8}
+
 \begin{function}{StrLCopy}
 \begin{function}{StrLCopy}
 \Declaration
 \Declaration
 Function StrLCopy (Dest,Source : PChar; MaxLen : Longint) : PChar;
 Function StrLCopy (Dest,Source : PChar; MaxLen : Longint) : PChar;
-
 \Description
 \Description
-
 Copies \var{MaxLen} characters from \var{Source} to \var{Dest}, and makes
 Copies \var{MaxLen} characters from \var{Source} to \var{Dest}, and makes
 \var{Dest} a null terminated string. 
 \var{Dest} a null terminated string. 
-
 \Errors
 \Errors
 No length checking is performed.
 No length checking is performed.
 \SeeAlso
 \SeeAlso
 \seef{StrCopy}, \seef{StrECopy}
 \seef{StrCopy}, \seef{StrECopy}
 \end{function}
 \end{function}
- 
-\latex{\lstinputlisting{stringex/ex5.pp}}
-\html{\input{stringex/ex5.tex}}
+
+\FPCexample{ex5}
+
 \begin{function}{StrLen}
 \begin{function}{StrLen}
 \Declaration
 \Declaration
 Function StrLen (p : PChar) : Longint;
 Function StrLen (p : PChar) : Longint;
-
 \Description
 \Description
-
 Returns the length of the null-terminated string \var{P}.
 Returns the length of the null-terminated string \var{P}.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seem{Length}{}
 \seem{Length}{}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex1.pp}}
-\html{\input{stringex/ex1.tex}}
+
+\FPCexample{ex1}
+
 \begin{function}{StrLIComp}
 \begin{function}{StrLIComp}
 \Declaration
 \Declaration
 Function StrLIComp (S1,S2 : PChar; L : Longint) : Longint;
 Function StrLIComp (S1,S2 : PChar; L : Longint) : Longint;
-
 \Description
 \Description
-
 Compares maximum \var{L} characters of the null-terminated strings \var{S1} 
 Compares maximum \var{L} characters of the null-terminated strings \var{S1} 
 and \var{S2}, ignoring case.
 and \var{S2}, ignoring case.
 The result is 
 The result is 
@@ -241,131 +225,119 @@ The result is
 \item 0 when \var{S1=S2}.
 \item 0 when \var{S1=S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \item A positive \var{Longint} when \var{S1>S2}.
 \end{itemize}
 \end{itemize}
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seef{StrLComp}, \seef{StrComp}, \seef{StrIComp}
 \seef{StrLComp}, \seef{StrComp}, \seef{StrIComp}
 \end{function}
 \end{function}
+
 For an example, see \seef{StrIComp}
 For an example, see \seef{StrIComp}
+
 \begin{function}{StrLower}
 \begin{function}{StrLower}
 \Declaration
 \Declaration
 Function StrLower (P : PChar) : PChar;
 Function StrLower (P : PChar) : PChar;
-
 \Description
 \Description
-
 Converts \var{P} to an all-lowercase string. Returns \var{P}.
 Converts \var{P} to an all-lowercase string. Returns \var{P}.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seem{Upcase}{}, \seef{StrUpper}
 \seem{Upcase}{}, \seef{StrUpper}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex14.pp}}
-\html{\input{stringex/ex14.tex}}
+
+\FPCexample{ex14}
+
 \begin{function}{StrMove}
 \begin{function}{StrMove}
 \Declaration
 \Declaration
 Function StrMove (Dest,Source : PChar; MaxLen : Longint) : PChar;
 Function StrMove (Dest,Source : PChar; MaxLen : Longint) : PChar;
-
 \Description
 \Description
-
 Copies \var{MaxLen} characters from \var{Source} to \var{Dest}. No
 Copies \var{MaxLen} characters from \var{Source} to \var{Dest}. No
 terminating null-character is copied.
 terminating null-character is copied.
 Returns \var {Dest}.
 Returns \var {Dest}.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seef{StrLCopy}, \seef{StrCopy}
 \seef{StrLCopy}, \seef{StrCopy}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex10.pp}}
-\html{\input{stringex/ex10.tex}}
+
+\FPCexample{ex10}
+
 \begin{function}{StrNew}
 \begin{function}{StrNew}
 \Declaration
 \Declaration
 Function StrNew (P : PChar) : PChar;
 Function StrNew (P : PChar) : PChar;
-
 \Description
 \Description
-
 Copies \var{P} to the Heap, and returns a pointer to the copy.
 Copies \var{P} to the Heap, and returns a pointer to the copy.
-
 \Errors
 \Errors
 Returns \var{Nil} if no memory was available for the copy.
 Returns \var{Nil} if no memory was available for the copy.
 \SeeAlso
 \SeeAlso
 \seem{New}{}, \seef{StrCopy}, \seep{StrDispose}
 \seem{New}{}, \seef{StrCopy}, \seep{StrDispose}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex16.pp}}
-\html{\input{stringex/ex16.tex}}
+
+\FPCexample{ex16}
+
 \begin{function}{StrPas}
 \begin{function}{StrPas}
 \Declaration
 \Declaration
 Function StrPas (P : PChar) : String;
 Function StrPas (P : PChar) : String;
-
 \Description
 \Description
-
 Converts a null terminated string in \var{P} to a Pascal string, and returns
 Converts a null terminated string in \var{P} to a Pascal string, and returns
 this string. The string is truncated at 255 characters.
 this string. The string is truncated at 255 characters.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
  \seef{StrPCopy}
  \seef{StrPCopy}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex3.pp}}
-\html{\input{stringex/ex3.tex}}
+
+\FPCexample{ex3}
+
 \begin{function}{StrPCopy}
 \begin{function}{StrPCopy}
 \Declaration
 \Declaration
 Function StrPCopy (Dest : PChar; Const Source : String) : PChar;
 Function StrPCopy (Dest : PChar; Const Source : String) : PChar;
-
 \Description
 \Description
-
 Converts the Pascal string in \var{Source} to a Null-terminated 
 Converts the Pascal string in \var{Source} to a Null-terminated 
 string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
 string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
 the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
 the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
-
 \Errors
 \Errors
 No length checking is performed.
 No length checking is performed.
 \SeeAlso
 \SeeAlso
  \seef{StrPas}
  \seef{StrPas}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex2.pp}}
-\html{\input{stringex/ex2.tex}}
+
+\FPCexample{ex2}
+
 \begin{function}{StrPos}
 \begin{function}{StrPos}
 \Declaration
 \Declaration
 Function StrPos (S1,S2 : PChar) : PChar;
 Function StrPos (S1,S2 : PChar) : PChar;
-
 \Description
 \Description
-
 Returns a pointer to the first occurrence of \var{S2} in \var{S1}.
 Returns a pointer to the first occurrence of \var{S2} in \var{S1}.
 If \var{S2} does not occur in \var{S1}, returns \var{Nil}.
 If \var{S2} does not occur in \var{S1}, returns \var{Nil}.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seem{Pos}{}, \seef{StrScan}, \seef{StrRScan}
 \seem{Pos}{}, \seef{StrScan}, \seef{StrRScan}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex15.pp}}
-\html{\input{stringex/ex15.tex}}
+
+\FPCexample{ex15}
+
 \begin{function}{StrRScan}
 \begin{function}{StrRScan}
 \Declaration
 \Declaration
 Function StrRScan (P : PChar; C : Char) : PChar;
 Function StrRScan (P : PChar; C : Char) : PChar;
-
 \Description
 \Description
-
 Returns a pointer to the last occurrence of the character \var{C} in the
 Returns a pointer to the last occurrence of the character \var{C} in the
 null-terminated string \var{P}. If \var{C} does not occur, returns
 null-terminated string \var{P}. If \var{C} does not occur, returns
 \var{Nil}.
 \var{Nil}.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seem{Pos}{}, \seef{StrScan}, \seef{StrPos}
 \seem{Pos}{}, \seef{StrScan}, \seef{StrPos}
 \end{function}
 \end{function}
+
+
 For an example, see \seef{StrScan}.
 For an example, see \seef{StrScan}.
+
+
 \begin{function}{StrScan}
 \begin{function}{StrScan}
 \Declaration
 \Declaration
 Function StrScan (P : PChar; C : Char) : PChar;
 Function StrScan (P : PChar; C : Char) : PChar;
-
 \Description
 \Description
-
 Returns a pointer to the first occurrence of the character \var{C} in the
 Returns a pointer to the first occurrence of the character \var{C} in the
 null-terminated string \var{P}. If \var{C} does not occur, returns
 null-terminated string \var{P}. If \var{C} does not occur, returns
 \var{Nil}.
 \var{Nil}.
@@ -375,19 +347,18 @@ None.
 \SeeAlso
 \SeeAlso
 \seem{Pos}{}, \seef{StrRScan}, \seef{StrPos}
 \seem{Pos}{}, \seef{StrRScan}, \seef{StrPos}
 \end{function}
 \end{function}
-\latex{\lstinputlisting{stringex/ex13.pp}}
-\html{\input{stringex/ex13.tex}}
+
+\FPCexample{ex13}
+
 \begin{function}{StrUpper}
 \begin{function}{StrUpper}
 \Declaration
 \Declaration
 Function StrUpper (P : PChar) : PChar;
 Function StrUpper (P : PChar) : PChar;
-
 \Description
 \Description
-
 Converts \var{P} to an all-uppercase string. Returns \var{P}.
 Converts \var{P} to an all-uppercase string. Returns \var{P}.
-
 \Errors
 \Errors
 None.
 None.
 \SeeAlso
 \SeeAlso
 \seem{Upcase}{}, \seef{StrLower}
 \seem{Upcase}{}, \seef{StrLower}
 \end{function}
 \end{function}
+
 For an example, see \seef{StrLower}
 For an example, see \seef{StrLower}