diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/parse/pathparse.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Wasabi/bfc/parse/pathparse.h')
-rw-r--r-- | Src/Wasabi/bfc/parse/pathparse.h | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/parse/pathparse.h b/Src/Wasabi/bfc/parse/pathparse.h new file mode 100644 index 00000000..67a22ffe --- /dev/null +++ b/Src/Wasabi/bfc/parse/pathparse.h @@ -0,0 +1,152 @@ +#ifndef _PATHPARSE_H +#define _PATHPARSE_H + +#include <bfc/ptrlist.h> +#include <bfc/string/bfcstring.h> +#include <bfc/string/StringW.h> + +/** + PathParser is a class that parses a DOS/Windows (example: C:\DOS) + style path as well as a UNIX style path (example: /usr/local/bin/). + + @short Path parser for Windows and UNIX style paths. + @author Nullsoft + @ver 1.0 +*/ +class PathParser +{ +public: + /** + When PathParser is instantiated, the contructor takes the path to + parse and the separators to use to parse the path. It will then + parse the path using the separators and make the parsed elements + available. If no separators are given \ and / are used. + + @param str The path to parse. + @param separators String that contains the separators to use. Single character separators only. + No delimiters between separators in the string. + */ + PathParser(const char *_str, const char *sep = "\\/", int uniquestrs = 0); + + void setString(const char *string, const char *separators = "\\/"); + + /** + Gets the number of path elements found in the path. + + @ret The number of path elements found. + */ + int getNumStrings(); + + /** + Gets the number of path elements found in the path. + + @ret The number of path elements found. + */ + char *enumString(int i); + + char *enumStringSafe(int i, char *def_val=""); + + /** + Gets the last path element from the parsed path. + + @ret The last path element from the parsed path. + */ + char *getLastString() { return enumString(getNumStrings()-1); } + +protected: + /** + Override available for pre-processing of the + string before it's split. This is done at the start + of the process() call. + + @param str A reference to the string to pre-process. + */ + virtual void preProcess(String &str) { } + + /** + Override available for post-processing of the pieces + of the command line that are obtained after it's + been split. + + @param str The command line piece to post-process. + */ + virtual void postProcess(char *str) { } + +private: + void process(); + int processed; + String str; + String separators; + PtrList<char> strings; + int uniques; +}; + +class PathParserW +{ +public: + /** + When PathParser is instantiated, the contructor takes the path to + parse and the separators to use to parse the path. It will then + parse the path using the separators and make the parsed elements + available. If no separators are given \ and / are used. + + @param str The path to parse. + @param separators String that contains the separators to use. Single character separators only. + No delimiters between separators in the string. + */ + PathParserW(const wchar_t *_str, const wchar_t *sep = L"\\/", int uniquestrs = 0); + + void setString(const wchar_t *string, const wchar_t *separators = L"\\/"); + + /** + Gets the number of path elements found in the path. + + @ret The number of path elements found. + */ + int getNumStrings(); + + /** + Gets the number of path elements found in the path. + + @ret The number of path elements found. + */ + wchar_t *enumString(int i); + + wchar_t *enumStringSafe(int i, wchar_t *def_val=L""); + + /** + Gets the last path element from the parsed path. + + @ret The last path element from the parsed path. + */ + wchar_t *getLastString() { return enumString(getNumStrings()-1); } + +protected: + /** + Override available for pre-processing of the + string before it's split. This is done at the start + of the process() call. + + @param str A reference to the string to pre-process. + */ + virtual void preProcess(StringW &str) { } + + /** + Override available for post-processing of the pieces + of the command line that are obtained after it's + been split. + + @param str The command line piece to post-process. + */ + virtual void postProcess(wchar_t *str) { } + +private: + void process(); + int processed; + StringW str; + StringW separators; + PtrList<wchar_t> strings; + int uniques; +}; + +#endif |