From 3fe7b3f72c545aae15ca08f85f5f5dad4c55817b Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 2 Nov 2014 11:36:21 +0100 Subject: [PATCH] BString: Add ScanWithFormat convenience method. --- headers/os/support/String.h | 6 ++++++ src/kits/support/String.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/headers/os/support/String.h b/headers/os/support/String.h index 60e6967e77..9e33c3cd66 100644 --- a/headers/os/support/String.h +++ b/headers/os/support/String.h @@ -61,6 +61,12 @@ public: va_list args) __attribute__((__format__(__printf__, 2, 0))); + int ScanWithFormat(const char* format, ...) + __attribute__((__format__(__scanf__, 2, 3))); + int ScanWithFormatVarArgs(const char* format, + va_list args) + __attribute__((__format__(__scanf__, 2, 0))); + // Substring copying BString& CopyInto(BString& into, int32 fromOffset, int32 length) const; diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index 5b4ac343b6..5533f03ebe 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -474,6 +474,25 @@ BString::SetToFormatVarArgs(const char* format, va_list args) } +int +BString::ScanWithFormat(const char* format, ...) +{ + va_list args; + va_start(args, format); + int result = ScanWithFormatVarArgs(format, args); + va_end(args); + + return result; +} + + +int +BString::ScanWithFormatVarArgs(const char* format, va_list args) +{ + return vsscanf(fPrivateData, format, args); +} + + // #pragma mark - Substring copying