Commit Graph

58 Commits

Author SHA1 Message Date
6ca7e2856b Modernize std::find with ranges 2024-10-10 15:28:11 -07:00
508ccc2054 IniFile: Migrate Common::CaseInsensitiveLess to StringUtil
Migrating `Common::CaseInsensitiveLess` to StringUtil.h will hopefully discourage rolling one's own solution in the future for case-insensitive associative containers when this (quite robust!) solution already exists.

`Common::CaseInsensitiveStringCompare::IsEqual` was removed in favor of using the `Common::CaseInsensitiveEquals` function.

The `a.size() != b.size()` condition in `Common::CaseInsensitiveEquals` can be removed, since `std::ranges::equal` already checks this condition (confirmed in libc++).
2024-09-21 23:15:42 -07:00
618b41a459 Use 'contains' method 2024-08-14 22:18:28 +02:00
e4caace6bb Common/IniFile: Move interface into Common namespace
Gets this out of the global namespace and into the Common namespace
2023-04-13 10:19:28 -04:00
f92541fbd9 StripSpaces: only strip spaces
StripWhitespace maintains old behavior
2022-07-25 18:40:12 -07:00
e149ad4f0a treewide: convert GPLv2+ license info to SPDX tags
SPDX standardizes how source code conveys its copyright and licensing
information. See https://spdx.github.io/spdx-spec/1-rationale/ . SPDX
tags are adopted in many large projects, including things like the Linux
kernel.
2021-07-05 04:35:56 +02:00
08c95883e9 Common/IniFile: Add Exists function for section name only 2020-02-29 01:39:36 -05:00
732032cdb2 Common/Core: Minor rvalue reference related cleanups. 2020-01-23 22:58:23 -06:00
a2a1e04fc9 StringUtil: Use std::string_view more 2019-07-23 14:49:12 +02:00
78d1716251 Common/IniFile: Make use of std::string_view where applicable
Now that the std::map less-than comparitor is capable of being used with
heterogenous lookup, we're able to convert many of the querying
functions that took std::string references over to std::string_view.

Now these functions may be used without potentially allocating a
std::string instance unnecessarily.
2019-06-16 18:20:08 -04:00
de7e9557dc Common/IniFile: Make CaseInsensitiveStringCompare usable with heterogenous lookup
Previously, when performing find() operations or indexing operations on
the section map, it would need to operate on a std::string key.

This means cases like:

map.find(some_string_view)

aren't usable, which kind of sucks, especially given for most cases, we
use regular string literals to perform operations in calling code.
However, since C++14, it's possible to use heterogenous lookup to avoid
needing to construct exact key types. In otherwords, we can perform the
above or use string literals without constructing a std::string instance
around them implicitly.

We simply need to specify a member type within our comparison struct
named is_transparent, to allow std::map to perform automatic type
deduction.

We also slightly alter the algorithm to an equivalent compatible with
std::string_view (which need not be null-terminated), as strcasecmp
requires null-terminated strings.

While we're at it, we can also provide a helper function to the struct
for comparing string equality rather than only less than. This allows
removing other usages of strcasecmp in other functions, allowing for the
transition of them to std::string_view.
2019-06-16 18:20:03 -04:00
c0c0e412e0 Core/ConfigManager: Use forward declarations where applicable
Avoids dragging in IniFile, EXI device and SI device headers in this header which is
quite widely used throughout the codebase.

This also uncovered a few cases where indirect inclusions were being
relied upon, which this also fixes.
2019-06-07 19:54:39 -04:00
617747e905 Merge pull request #8113 from lioncash/ini-key
Common/IniFile: Simplify Set()
2019-05-23 12:15:30 +02:00
2ae370fc37 IniFile: Prevent potential out-of-bounds access in ParseLine()
While current usages of ParseLine aren't problematic, this is still a
public function that can be used for other purposes. Essentially makes
the function handle potential external inputs a little nicer.
2019-05-22 21:09:11 -04:00
869acb96c6 Common/IniFile: Simplify Set()
We can just utilize map's insert_or_assign() function and check the
return value to determine whether or not we need to insert the key into
the keys_order vector.
2019-05-22 20:58:49 -04:00
49fe9f5db1 Use empty instead of size 2019-02-13 00:03:49 +01:00
a464025bba IniFile: Minor cleanup. Removed unused function. Improved template usage. 2018-12-26 20:15:32 -06:00
7e79bf97ab IniFile: Use templates for Get()
Gets rid of duplicated code.
2018-06-03 14:53:56 +02:00
cba32b12e7 IniFile: Use templates for Set() 2018-06-03 14:53:56 +02:00
fc0193c4b1 Move Config ValueToString to StringUtil
An identical implementation is used by IniFile, so move those functions
to StringUtil. A future commit will modify IniFile to use them.
2018-06-03 14:10:52 +02:00
90f8265497 Replace StringFromInt with std::to_string
Updated version of #47. Android should support to_string now that
we use a modern version of libc++ when building.
2017-07-05 13:49:33 +02:00
cf94ce6305 Add a namespace to OpenFStream
For consistency with the other functions in FileUtil.h.
2017-06-15 21:34:04 +02:00
29ca22905b IniFile: Replace a character erase with pop_back()
Same thing, more straightforward.
2017-03-22 19:32:10 -04:00
35959bdaf9 IniFile: Replace string joining code with JoinString 2017-03-22 19:30:15 -04:00
b92871111a IniFile: std::move a std::string in GetLines
Also gets rid of an unnecessary string copy.
2017-03-22 19:09:25 -04:00
dbdf693c81 IniFile: Use character literals instead of string literals where applicable
Character overloads are generally better overall (range checks aren't
necessary, etc).
2017-03-22 19:03:17 -04:00
d8998b6392 IniFile: Provide an rvalue reference overload for SetLines
Allows moving in vectors instead of performing an unnecessary copy.
2017-03-22 18:49:13 -04:00
46d74a7760 IniFile: Make Section's string constructor instances take strings by value
As the name is immediately stored into a class member, a move here is a
better choice.

This also moves the constructor implementations into the cpp file to
avoid an otherwise unnecessary inclusion in the header. This is also
likely a better choice as Section contains several non-trivial members,
so this would avoid potentially inlining a bunch of setup and teardown
code related to them as a side-benefit.
2017-03-22 18:47:19 -04:00
ead8be9d19 Move IniFile section chunk handling to IniFile::Section 2017-03-05 15:47:23 +01:00
beec40f178 IniFile: Handle s64/u64 values 2017-02-25 00:03:20 -05:00
bc2b9f4c3c Translate Swedish in example strings to English 2017-02-04 22:51:01 +01:00
3570c7f03a Reformat all the things. Have fun with merge conflicts. 2016-06-24 10:43:46 +02:00
822cf2bcbf IniFile: Mark getter functions as const 2015-08-19 22:27:18 -04:00
990d61b786 Skip reading UTF-8 BOM at the beginning of INI files 2015-06-05 18:32:58 +02:00
35ca27f1cd Fix bug where Gecko codes would be "enabled by default"
Actually caused by IniFiles::GetLines leaving the output vector in its
old state if the section wasn't found, and Gecko::LoadCodes not checking
the return value.  Fix by moving lines->clear() up.
2015-06-02 19:04:04 -04:00
30ebb2459e Set copyright year to when a file was created 2015-05-25 13:22:31 +02:00
cefcb0ace9 Update license headers to GPLv2+ 2015-05-25 13:22:31 +02:00
eacf741051 DolphinWX/Common: Change some find_first_of usages to find
It's unnecessary to use find_first_of when all you're searching for is a single character.
2015-03-24 08:32:44 -04:00
e07679114b Use emplace_* functions where in-place construction is preferable 2015-02-04 11:39:08 -05:00
b25e1a2eb4 Various formatting and consistency fixes 2014-11-13 22:42:18 -05:00
345b608d64 Change IniFile::Section::Set() with default value to use a template. 2014-09-04 03:29:49 -04:00
6bdc32c54a Add the VideoCommon PostProcessing class.
This class loads all the common PP shader configuration options and passes those options through to a inherited class that OpenGL or D3D will have.
Makes it so all the common code for PP shaders is in VideoCommon instead of duplicating the code across each backend.
2014-08-13 01:05:10 -05:00
516369594f Store ini sections in a std::list (rather than vector) to prevent unexpected pointer invalidation with use of GetOrCreateSection. 2014-06-24 12:37:38 -05:00
f05d3f6e5d Use only section-based ini reading. 2014-06-16 01:31:23 -04:00
eca70d1562 Get rid of the temporary buffer in IniFile's Load function.
std::getline is the string-based equivalent.
2014-05-28 20:26:15 -04:00
80ab567a5b When reading an ini file, if there is an error, check if it is simply because the eof was reached. 2014-05-28 14:06:18 -04:00
0782d106db Check for errors when reading lines from ini files.
Fixes issue 7283.
2014-05-23 03:17:19 -04:00
d0bd4119d1 Use size_t in std::string operations in IniFile.cpp, not int 2014-05-14 20:38:08 -04:00
fa3cc05753 Turn some non-const refs into pointers 2014-03-17 02:55:57 +01:00
31cfc73a09 Fixes spacing for "for", "while", "switch" and "if"
Also moved && and || to ends of lines instead of start.
Fixed misc vertical alignments and some { needed newlining.
2014-03-11 00:35:07 +13:00