2424
2525#include " Context.hpp"
2626
27- #include < cstring>
28- #include < memory>
2927#include < algorithm>
3028#include < map>
29+ #include < memory>
3130
3231namespace
3332{
@@ -42,30 +41,13 @@ inline DWORD updateReaderNamesBuffer(const SCARDCONTEXT ctx, string_t::value_typ
4241 return bufferLengthOut;
4342}
4443
45- std::vector<const string_t ::value_type*> getReaderNamePointerList (const string_t & readerNames)
46- {
47- auto readerNamePointerList = std::vector<const string_t ::value_type*> {};
48-
49- if (readerNames.empty ())
50- return readerNamePointerList;
51-
52- // Reader names are \0 separated and end with double \0.
53- #ifdef _WIN32
54- for (const string_t ::value_type* name = readerNames.c_str (); *name; name += wcslen (name) + 1 ) {
55- #else
56- for (const string_t ::value_type* name = readerNames.c_str (); *name; name += strlen (name) + 1 ) {
57- #endif
58- readerNamePointerList.push_back (name);
59- }
60-
61- return readerNamePointerList;
62- }
63-
6444std::vector<SCARD_READERSTATE> getReaderStates (const SCARDCONTEXT ctx, const string_t & readerNames)
6545{
6646 auto readerStates = std::vector<SCARD_READERSTATE> {};
67- for (const auto & readerNamePointer : getReaderNamePointerList (readerNames)) {
68- readerStates.push_back ({readerNamePointer,
47+ // Reader names are \0 separated and end with double \0.
48+ for (const auto * name = readerNames.c_str (); *name;
49+ name += string_t::traits_type::length (name) + 1 ) {
50+ readerStates.push_back ({name,
6951 nullptr ,
7052 SCARD_STATE_UNAWARE,
7153 SCARD_STATE_UNAWARE,
@@ -76,7 +58,7 @@ std::vector<SCARD_READERSTATE> getReaderStates(const SCARDCONTEXT ctx, const str
7658 }
7759
7860 if (readerStates.empty ())
79- return {} ;
61+ return readerStates ;
8062
8163 SCard (GetStatusChange, ctx, 0U , readerStates.data (), DWORD (readerStates.size ()));
8264
0 commit comments