From cdf8de1c026efbe1f1b521c7fae5b9b284e1ba50 Mon Sep 17 00:00:00 2001 From: chatty Date: Wed, 22 Dec 1993 12:24:36 +0000 Subject: Added CcuString (const char*, int); Added Assign (const char*, int) --- utils/String.cc | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'utils/String.cc') diff --git a/utils/String.cc b/utils/String.cc index 3da5d7d..f6b7e4a 100644 --- a/utils/String.cc +++ b/utils/String.cc @@ -3,10 +3,10 @@ * * by Stephane Chatty * - * Copyright 1992 + * Copyright 1992, 1993 * Centre d'Etudes de la Navigation Aerienne (CENA) * - * CcuString allocation and copying + * String allocation and copying * * $Id$ * $CurLog$ @@ -38,9 +38,10 @@ NewString (const char* s) /*? Allocate a string of \var{n} characters, -copy the \var{n} first characters of \var{s} in it, +copy the \var{n} first characters of \var{s} in it, and return the address. The returned string is null terminated. -If \var{s} is 0, return 0. +If \var{s} is 0, return 0. If it is shorter than \var{n} characters, +the new string is padded with null characters. ?*/ char* NewString (const char* s, int n) @@ -107,8 +108,18 @@ CcuString :: CcuString () Build a \typ{CcuString} from \var{s}. \var{s} can be null. ?*/ CcuString :: CcuString (const char* s) +: Str (NewString (s)) +{ +} + +/*? +Build a \typ{CcuString} from the \var{n} first characters of \var{s}. \var{s} can be null. +If it is shorter than \var{n} characters, +the new string is padded with null characters. +?*/ +CcuString :: CcuString (const char* s, int n) +: Str (NewString (s, n)) { - Str = NewString (s); } /*? @@ -116,8 +127,8 @@ Create a \typ{CcuString} suitable for storing at most \var{n} characters, and initialize it to the null string. ?*/ CcuString :: CcuString (int n) +: Str (NewString (n)) { - Str = NewString (n); *Str = '\0'; } @@ -125,8 +136,8 @@ CcuString :: CcuString (int n) Create a new \typ{CcuString} by copying \var{s}. ?*/ CcuString :: CcuString (const CcuString& s) +: Str (NewString (s)) { - Str = NewString (s); } /*? @@ -144,6 +155,16 @@ CcuString :: ~CcuString () FreeString (Str); } +#ifdef DOC +/*? +Return the value of a string. +?*/ +CcuString :: operator const char* () const +{ +} +#endif + + /*? Copy \var{s} into this string. The old string is freed. @@ -178,15 +199,25 @@ CcuString :: operator = (const CcuShadowString& s) return *this; } -#ifdef DOC /*? -Return the value of a string. +Assign to a string the \var{n} first characters of \var{s}. +\var{s} can be null. +If it is shorter than \var{n} characters, +the new string is padded with null characters. ?*/ -CcuString :: operator const char* () const +CcuString& +CcuString :: Assign (const char* s, int n) { + if (Str != s) { + FreeString (Str); + Str = NewString (s, n); + } + return *this; } -#endif +/*? +Compute the length of a string. +?*/ int CcuString :: Length () const { -- cgit v1.1