Skip to content

Commit 6982ca5

Browse files
committed
Util/StringCompare: add string_view overloads
1 parent 4e0ed22 commit 6982ca5

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/Util/StringCompare.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2018 Max Kellermann <[email protected]>
2+
* Copyright 2013-2020 Max Kellermann <[email protected]>
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions

src/Util/StringCompare.hxx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2018 Max Kellermann <[email protected]>
2+
* Copyright 2013-2020 Max Kellermann <[email protected]>
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -38,13 +38,31 @@
3838
#include "WStringCompare.hxx"
3939
#endif
4040

41+
#include <string_view>
42+
4143
gcc_pure gcc_nonnull_all
4244
static inline bool
4345
StringIsEmpty(const char *string) noexcept
4446
{
4547
return *string == 0;
4648
}
4749

50+
gcc_pure
51+
static inline bool
52+
StringIsEqual(std::string_view a, std::string_view b) noexcept
53+
{
54+
return a.size() == b.size() &&
55+
StringIsEqual(a.data(), b.data(), b.size());
56+
}
57+
58+
gcc_pure
59+
static inline bool
60+
StringIsEqualIgnoreCase(std::string_view a, std::string_view b) noexcept
61+
{
62+
return a.size() == b.size() &&
63+
StringIsEqualIgnoreCase(a.data(), b.data(), b.size());
64+
}
65+
4866
gcc_pure gcc_nonnull_all
4967
static inline bool
5068
StringStartsWith(const char *haystack, StringView needle) noexcept

src/Util/WStringCompare.hxx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2018 Max Kellermann <[email protected]>
2+
* Copyright 2013-2020 Max Kellermann <[email protected]>
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -34,6 +34,8 @@
3434
#include "WStringAPI.hxx"
3535
#include "Compiler.h"
3636

37+
#include <string_view>
38+
3739
#include <wchar.h>
3840

3941
gcc_pure gcc_nonnull_all
@@ -43,6 +45,14 @@ StringIsEmpty(const wchar_t *string) noexcept
4345
return *string == 0;
4446
}
4547

48+
gcc_pure
49+
static inline bool
50+
StringIsEqual(std::wstring_view a, std::wstring_view b) noexcept
51+
{
52+
return a.size() == b.size() &&
53+
StringIsEqual(a.data(), b.data(), b.size());
54+
}
55+
4656
gcc_pure gcc_nonnull_all
4757
static inline bool
4858
StringStartsWith(const wchar_t *haystack, WStringView needle) noexcept

0 commit comments

Comments
 (0)