Skip to content

Commit de72dc6

Browse files
committed
#101 - Test CppStringT::TransTable constructor #9 with char and wchar_t
Tested.
1 parent 6e166c8 commit de72dc6

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

‎cpp-strings-tests/cpp-strings-tests.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ namespace cppstringstests
152152
Assert::AreEqual(CppWString(L'c').c_str(), wt[L'c'].c_str());
153153
}
154154

155+
TEST_METHOD(constructor_09)
156+
{
157+
std::string keys("abC");
158+
std::vector<std::string> values{ "AA", "BBB", "c" };
159+
std::string not_translated("dE");
160+
pcs::CppString::TransTable t(keys.begin(), keys.end(), values.begin(), values.end(), not_translated.cbegin(), not_translated.cend());
161+
Assert::AreEqual(CppString("AA").c_str(), t['a'].c_str());
162+
Assert::AreEqual(CppString("BBB").c_str(), t['b'].c_str());
163+
Assert::AreEqual(CppString('c').c_str(), t['C'].c_str());
164+
Assert::AreEqual(CppString().c_str(), t['d'].c_str());
165+
Assert::AreEqual(CppString().c_str(), t['E'].c_str());
166+
Assert::AreEqual(CppString('c').c_str(), t['c'].c_str());
167+
168+
std::wstring wkeys(L"abC");
169+
std::vector<std::wstring> wvalues{ L"AA", L"BBB", L"c" };
170+
std::wstring wnot_translated(L"dE");
171+
pcs::CppWString::TransTable wt(wkeys.begin(), wkeys.end(), wvalues.begin(), wvalues.end(), wnot_translated.cbegin(), wnot_translated.cend());
172+
Assert::AreEqual(CppWString(L"AA").c_str(), wt[L'a'].c_str());
173+
Assert::AreEqual(CppWString(L"BBB").c_str(), wt[L'b'].c_str());
174+
Assert::AreEqual(CppWString(L'c').c_str(), wt[L'C'].c_str());
175+
Assert::AreEqual(CppWString().c_str(), wt[L'd'].c_str());
176+
Assert::AreEqual(CppWString().c_str(), wt[L'E'].c_str());
177+
Assert::AreEqual(CppWString(L'c').c_str(), wt[L'c'].c_str());
178+
}
179+
155180

156181
};
157182
}

‎cpp-strings/cppstrings.h‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,18 @@ namespace pcs // i.e. "pythonic c++ strings"
271271
* contained in string not_translated are associated in the
272272
* translation table with the empty string.
273273
*/
274-
template<class KeyIt, class ValueIt>
275-
inline TransTable(KeyIt first_key, KeyIt last_key,
276-
ValueIt first_value, ValueIt last_value,
277-
KeyIt first_not_translated, KeyIt last_not_translated)
274+
template<class Key1It, class ValueIt, class Key2It>
275+
inline TransTable(Key1It first_key, Key1It last_key,
276+
ValueIt first_value, ValueIt last_value,
277+
Key2It first_not_translated, Key2It last_not_translated)
278278
{
279-
KeyIt key_it{ first_key };
279+
Key1It key1_it{ first_key };
280280
ValueIt val_it{ first_value };
281-
while (key_it != last_key && val_it != last_value)
282-
m_table[*key_it++] = value_type(*val_it++);
283-
key_it = first_not_translated;
284-
while (key_it != last_not_translated)
285-
m_table[*key_it++] = CppStringT();
281+
while (key1_it != last_key && val_it != last_value)
282+
m_table[*key1_it++] = value_type(*val_it++);
283+
Key2It key2_it{ first_not_translated };
284+
while (key2_it != last_not_translated)
285+
m_table[*key2_it++] = CppStringT();
286286
}
287287

288288
/** \brief Creates a TransTable from two string views (#10).

0 commit comments

Comments
 (0)