<div dir="ltr">Yea I don't like the stateful modifiers.  It reminds me of std::iostream where you had to do << std::hex(foo) << 12345 << std::dec(foo).  I have an idea in my head for how you could reduce everything to one function, but it's a lot of work.  I could imagine something like this though:<div><br></div><div>llvm::StringSwitch<int>(S).Case(Lower("int", "double", "foo"), Value(7)).</div><div><br></div><div>If you do it like this, Lower could be variadic, and it would remove all the overloads and code duplication and you could just have 3 or 4 functions in the class.  Case, StartsWith, EndsWith, and maybe Contains.  Perhaps you could even overload the operator() so you could write it like this:</div><div><br></div><div>llvm::StringSwitch<int>(S)</div><div>    (CaseLower("int", "double", "foo"), Value(7))<br></div><div>    (Case("ABC", "DEF", "GHI"), Value(42))</div><div>    (StartsWith("Test", "TeSt"), Value(84));</div><div><br></div><div>Anyway, it's a lot of work, and for now I don't think we should lose the ability to have Case and CaseLower on the same switch.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 3, 2016 at 1:35 PM Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Well, I don't have data points to make a decision, so if you like that way I don't object. The other way would be to make it switchable, e.g.<div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">  auto Ret = StringSwtich<T>(Str)</div><div class="gmail_msg">    .Case("case-sensitive", foo)</div><div class="gmail_msg">    .CaseInsensitive()</div><div class="gmail_msg">    .Case("case-insensitive", bar)</div><div class="gmail_msg">    .CaseSensitive()</div><div class="gmail_msg">    ...</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">but it's probably too much.</div></div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Mon, Oct 3, 2016 at 1:30 PM, Zachary Turner <span dir="ltr" class="gmail_msg"><<a href="mailto:zturner@google.com" class="gmail_msg" target="_blank">zturner@google.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">That is true, but it would make it impossible to have both case sensitive and case-insensitive cases in the same switch.  For example, the following is currently possible:<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">StringSwitch<int>(s).Case("one").CaseLower("two");</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I'm not sure how useful this would be, but I see no reason not to allow it.  One idea might be to templatize the member function itself, and give it a default value of case sensitive.  But then you still have to write:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">StringSwitch<int>(s).Case<>("one").Case<false>("two");</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">which might be awkward.  thoughts?</div></div><div class="m_4911256152539757621HOEnZb gmail_msg"><div class="m_4911256152539757621h5 gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Mon, Oct 3, 2016 at 1:26 PM Rui Ueyama <<a href="mailto:ruiu@google.com" class="gmail_msg" target="_blank">ruiu@google.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">It just comes to my mind that you could make StringSwitch case-insensitive instead of adding case-insensitive versions of StartsWith, Case and Cases. It'd probably be something like<div class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"><br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"></div><div class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">  auto Ret = StringSwtich<T>(Str, /*CaseInsensitive=*/true)</div><div class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">      .Case("foo", bar) //  "foo" is compared in the insensitive manner</div><div class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">      ...</div><div class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"><br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"></div><div class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">With this, you don't need to double the number of member functions.</div></div><div class="gmail_extra m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"><br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"><div class="gmail_quote m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">On Mon, Oct 3, 2016 at 1:15 PM, Zachary Turner <span dir="ltr" class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"><<a href="mailto:zturner@google.com" class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg" target="_blank">zturner@google.com</a>></span> wrote:<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"><blockquote class="gmail_quote m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">zturner updated this revision to Diff 73327.<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
zturner added a comment.<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
Unit tests for the case-sensitive versions were removed and submitted separately.  The `Optional` variant of the function is removed and will be submitted later.  This patch only contains case-insensitive versions of the functions with associated unit tests.<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
<a href="https://reviews.llvm.org/D24686" rel="noreferrer" class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg" target="_blank">https://reviews.llvm.org/D24686</a><br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
Files:<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
  include/llvm/ADT/StringSwitch.h<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
  unittests/ADT/StringSwitchTest.cpp<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
<br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg">
</blockquote></div><br class="m_4911256152539757621m_-4118106945002421305gmail_msg gmail_msg"></div>
</blockquote></div>
</div></div></blockquote></div><br class="gmail_msg"></div>
</blockquote></div>