diff options
Diffstat (limited to '')
| -rw-r--r-- | src/fstring.h | 44 | ||||
| -rw-r--r-- | src/tests/fstrformat.cpp | 12 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/fstring.h b/src/fstring.h index de34cb0..2a18362 100644 --- a/src/fstring.h +++ b/src/fstring.h | |||
| @@ -681,6 +681,50 @@ namespace Bu | |||
| 681 | appendChunk( pNew ); | 681 | appendChunk( pNew ); |
| 682 | } | 682 | } |
| 683 | 683 | ||
| 684 | void format( const char *sFrmt, ...) | ||
| 685 | { | ||
| 686 | clear(); | ||
| 687 | |||
| 688 | va_list ap; | ||
| 689 | va_start( ap, sFrmt ); | ||
| 690 | |||
| 691 | long iLen = vsnprintf( NULL, 0, sFrmt, ap ); | ||
| 692 | |||
| 693 | Chunk *pNew = newChunk( iLen ); | ||
| 694 | vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); | ||
| 695 | appendChunk( pNew ); | ||
| 696 | |||
| 697 | va_end( ap ); | ||
| 698 | } | ||
| 699 | |||
| 700 | void formatAppend( const char *sFrmt, ...) | ||
| 701 | { | ||
| 702 | va_list ap; | ||
| 703 | va_start( ap, sFrmt ); | ||
| 704 | |||
| 705 | long iLen = vsnprintf( NULL, 0, sFrmt, ap ); | ||
| 706 | |||
| 707 | Chunk *pNew = newChunk( iLen ); | ||
| 708 | vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); | ||
| 709 | appendChunk( pNew ); | ||
| 710 | |||
| 711 | va_end( ap ); | ||
| 712 | } | ||
| 713 | |||
| 714 | void formatPrepend( const char *sFrmt, ...) | ||
| 715 | { | ||
| 716 | va_list ap; | ||
| 717 | va_start( ap, sFrmt ); | ||
| 718 | |||
| 719 | long iLen = vsnprintf( NULL, 0, sFrmt, ap ); | ||
| 720 | |||
| 721 | Chunk *pNew = newChunk( iLen ); | ||
| 722 | vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); | ||
| 723 | prependChunk( pNew ); | ||
| 724 | |||
| 725 | va_end( ap ); | ||
| 726 | } | ||
| 727 | |||
| 684 | /** | 728 | /** |
| 685 | * Function the archiver calls to archive your FString. | 729 | * Function the archiver calls to archive your FString. |
| 686 | *@param ar (Archive) The archive which is archiving your FString. | 730 | *@param ar (Archive) The archive which is archiving your FString. |
diff --git a/src/tests/fstrformat.cpp b/src/tests/fstrformat.cpp new file mode 100644 index 0000000..dbf6133 --- /dev/null +++ b/src/tests/fstrformat.cpp | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #include "bu/fstring.h" | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | int main() | ||
| 5 | { | ||
| 6 | Bu::FString s; | ||
| 7 | |||
| 8 | s.format("%d, %f, \'%s\'", 144, 12.5, "bob" ); | ||
| 9 | |||
| 10 | printf("test: %s\n", s.getStr() ); | ||
| 11 | } | ||
| 12 | |||
