summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty1993-12-22 12:24:36 +0000
committerchatty1993-12-22 12:24:36 +0000
commitcdf8de1c026efbe1f1b521c7fae5b9b284e1ba50 (patch)
treebeb03458da9452bb695e5c7cfbf5ebdd864f57f4
parent9ee441b8c64cbd39bdd79e9f55e8388390ea6e14 (diff)
downloadivy-league-cdf8de1c026efbe1f1b521c7fae5b9b284e1ba50.zip
ivy-league-cdf8de1c026efbe1f1b521c7fae5b9b284e1ba50.tar.gz
ivy-league-cdf8de1c026efbe1f1b521c7fae5b9b284e1ba50.tar.bz2
ivy-league-cdf8de1c026efbe1f1b521c7fae5b9b284e1ba50.tar.xz
Added CcuString (const char*, int);
Added Assign (const char*, int)
-rw-r--r--utils/String.cc53
-rw-r--r--utils/String.h4
2 files changed, 45 insertions, 12 deletions
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
{
diff --git a/utils/String.h b/utils/String.h
index 4aa83ca..42509d3 100644
--- a/utils/String.h
+++ b/utils/String.h
@@ -33,14 +33,16 @@ private:
public:
inline CcuString () { Str = 0; }
CcuString (const char*);
+ CcuString (const char*, int);
CcuString (int);
CcuString (const CcuString&);
CcuString (const CcuShadowString&);
~CcuString ();
+inline operator const char* () const { return Str; }
CcuString& operator = (const CcuString&);
CcuString& operator = (const char*);
CcuString& operator = (const CcuShadowString&);
-inline operator const char* () const { return Str; }
+ CcuString& Assign (const char*, int);
int Length () const;
};