octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #48726] caseless_str overloads compare and inv


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #48726] caseless_str overloads compare and inverts meaning
Date: Tue, 9 Aug 2016 12:19:22 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

Update of bug #48726 (project octave):

                Category:                    None => Libraries              
              Item Group:                    None => Other                  
                  Status:                    None => Confirmed              

    _______________________________________________________

Follow-up Comment #2:

I agree with you Carnë. The only function used according to Doxygen is
caseless_str::compare() and this in turn is mainly used in
libinterp/corefcn/graphics.cc. Maybe we can establish a short inline function
like "match_case_insensitive()" below there? This should not confuse with the
semantics of std::string::compare() and is simple, stupid, short. Do we have a
string utility header as alternative placement? Anyway, this function, as like
as the existing one, works only for non-Unicode characters.


#include <iostream>
#include <string>
#include <algorithm>

bool match_case_insensitive(std::string const& a, std::string const& b) {
  if (a.length() == b.length()) {
    return std::equal(a.begin(), a.end(), b.begin(),
      [](unsigned char ca, unsigned char cb) {
        return std::tolower(ca) == std::tolower(cb); });
  } else {
    return false;
  }
}

int main (){
  std::string s1 = "hallo";
  std::string s2 = "hallo";
  std::string s3 = "hAlLo";
  std::cout << s1.compare(s2) << " "
            << match_case_insensitive(s1, s2) << " "
            << s1.compare(s2) << std::endl;
  std::cout << s1.compare(s3) << " "
            << match_case_insensitive(s1, s3) << " "
            << s1.compare(s3) << std::endl;
  return 0;
}


Source:
https://stackoverflow.com/questions/23943728/case-insensitive-standard-string-comparison-in-c

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?48726>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]