blob: c649c64d62ac019b43ff00417c9cfbc0ae86cd50 [file] [log] [blame]
Jamie Madill8c5aeb62015-05-21 08:17:18 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6// string_utils:
7// String helper functions.
8//
9
10#ifndef LIBANGLE_STRING_UTILS_H_
11#define LIBANGLE_STRING_UTILS_H_
12
13#include <string>
14#include <vector>
15
Jamie Madill8b9b7922016-05-19 13:13:37 -040016#include "common/Optional.h"
17
Jamie Madill8c5aeb62015-05-21 08:17:18 -040018namespace angle
19{
20
Corentin Wallez47ac69c2015-11-24 11:15:57 -050021extern const char kWhitespaceASCII[];
22
23enum WhitespaceHandling
24{
25 KEEP_WHITESPACE,
26 TRIM_WHITESPACE,
27};
28
29enum SplitResult
30{
31 SPLIT_WANT_ALL,
32 SPLIT_WANT_NONEMPTY,
33};
34
35std::vector<std::string> SplitString(const std::string &input,
36 const std::string &delimiters,
37 WhitespaceHandling whitespace,
38 SplitResult resultType);
Jamie Madill8c5aeb62015-05-21 08:17:18 -040039
40void SplitStringAlongWhitespace(const std::string &input,
41 std::vector<std::string> *tokensOut);
42
Corentin Wallez47ac69c2015-11-24 11:15:57 -050043std::string TrimString(const std::string &input, const std::string &trimChars);
44
Jamie Madill8c5aeb62015-05-21 08:17:18 -040045bool HexStringToUInt(const std::string &input, unsigned int *uintOut);
46
47bool ReadFileToString(const std::string &path, std::string *stringOut);
48
Jamie Madill8b9b7922016-05-19 13:13:37 -040049Optional<std::vector<wchar_t>> WidenString(size_t length, const char *cString);
Sami Väisänen46eaa942016-06-29 10:26:37 +030050
51// Check if the string str begins with the given prefix.
52// Prefix may not be NULL and needs to be NULL terminated.
53// The comparison is case sensitive.
54bool BeginsWith(const std::string &str, const char *prefix);
55
56// Check if the string str begins with the given prefix.
57// str and prefix may not be NULL and need to be NULL terminated.
58// The comparison is case sensitive.
59bool BeginsWith(const char *str, const char *prefix);
60
61// Check if the string str ends with the given suffix.
62// Suffix may not be NUL and needs to be NULL terminated.
63// The comparison is case sensitive.
64bool EndsWith(const std::string& str, const char* suffix);
Jamie Madill8c5aeb62015-05-21 08:17:18 -040065}
66
67#endif // LIBANGLE_STRING_UTILS_H_