aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-09-04 08:49:45 +0000
committerMike Buland <eichlan@xagasoft.com>2007-09-04 08:49:45 +0000
commita3cb276a2b048ce94b04e95b3ac87f323e075712 (patch)
tree328d5652de04f8f4fad8a5f533447b2e64466420 /src
parent425502d5d07b4e508befa5aba0a266eeb8a6cd31 (diff)
downloadlibbu++-a3cb276a2b048ce94b04e95b3ac87f323e075712.tar.gz
libbu++-a3cb276a2b048ce94b04e95b3ac87f323e075712.tar.bz2
libbu++-a3cb276a2b048ce94b04e95b3ac87f323e075712.tar.xz
libbu++-a3cb276a2b048ce94b04e95b3ac87f323e075712.zip
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.
Diffstat (limited to '')
-rw-r--r--src/fstring.h26
1 files changed, 26 insertions, 0 deletions
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 @@
4#include <stdint.h> 4#include <stdint.h>
5#include <string> 5#include <string>
6#include <memory> 6#include <memory>
7#include <wordexp.h>
7#include "bu/archival.h" 8#include "bu/archival.h"
8#include "bu/archive.h" 9#include "bu/archive.h"
9#include "bu/hash.h" 10#include "bu/hash.h"
@@ -397,6 +398,31 @@ namespace Bu
397 append( pData, nSize ); 398 append( pData, nSize );
398 } 399 }
399 400
401 void expand()
402 {
403 flatten();
404
405 wordexp_t result;
406
407 /* Expand the string for the program to run. */
408 switch (wordexp (pFirst->pData, &result, 0))
409 {
410 case 0: /* Successful. */
411 {
412 set( result.we_wordv[0] );
413 wordfree( &result );
414 return;
415 }
416 break;
417 case WRDE_NOSPACE:
418 /* If the error was `WRDE_NOSPACE',
419 then perhaps part of the result was allocated. */
420 wordfree (&result);
421 default: /* Some other error. */
422 return;
423 }
424 }
425
400 /** 426 /**
401 * Assignment operator. 427 * Assignment operator.
402 *@param rSrc (const MyType &) The FString to set your FString to. 428 *@param rSrc (const MyType &) The FString to set your FString to.