From a3cb276a2b048ce94b04e95b3ac87f323e075712 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 4 Sep 2007 08:49:45 +0000 Subject: Added the Bu::FString::expand() function, which expands the string in place using system variables and special tokens, such as ~name and ~/... I like this, and think that it's ample precedent for adding things like format(), formatAppend(), and formatPrepend(), which would all rock. --- src/fstring.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/fstring.h b/src/fstring.h index 63e1e1a..9de6a56 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "bu/archival.h" #include "bu/archive.h" #include "bu/hash.h" @@ -397,6 +398,31 @@ namespace Bu append( pData, nSize ); } + void expand() + { + flatten(); + + wordexp_t result; + + /* Expand the string for the program to run. */ + switch (wordexp (pFirst->pData, &result, 0)) + { + case 0: /* Successful. */ + { + set( result.we_wordv[0] ); + wordfree( &result ); + return; + } + break; + case WRDE_NOSPACE: + /* If the error was `WRDE_NOSPACE', + then perhaps part of the result was allocated. */ + wordfree (&result); + default: /* Some other error. */ + return; + } + } + /** * Assignment operator. *@param rSrc (const MyType &) The FString to set your FString to. -- cgit v1.2.3