Code Monkey home page Code Monkey logo

Comments (7)

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

nah i'll just write a little C stub to take the buffer pointer. Although i like C++'s fanciness sometimes it's too much imo

from polyhook_2_0.

no-realm avatar no-realm commented on August 11, 2024

Ok, it's your project.
Most of the time though, it will be as fast if not faster than a quick implementation you write yourself. It's not like the above is complicated or fancy. The lambda could also be replaced by a (struct) functor.
The only drawback I see is that std::wstring_view allocated memory for the two pointers to start and end.
And it also defeats the purpose of stating that this is a C++17 library IMO.

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

I appreciate your interest, I'd use string view if it had a icompare, but it doesn't unfortunately. Since this is the case I'd rather make a utility that doesn't require the construction, because it doesn't benefit us and reduce complexity. I use lots of c++ 17 goodies elsewhere where this is the case.

I'm honestly shocked case insensitive wide string compares aren't standard, it's annoying as fuck

from polyhook_2_0.

no-realm avatar no-realm commented on August 11, 2024

Then how about creating a modified char_traits<> type which compares case-insensitively.
More details here: https://stackoverflow.com/questions/11635/case-insensitive-string-comparison-in-c/2886589#2886589
Something like this:

// Derive from std::char_traits<wchar_t>.
struct ci_wchar_traits : public std::char_traits<wchar_t> {
    static bool eq(wchar_t c1, wchar_t c2) { return towupper(c1) == towupper(c2); }
    static bool ne(wchar_t c1, wchar_t c2) { return towupper(c1) != towupper(c2); }
    static bool lt(wchar_t c1, wchar_t c2) { return towupper(c1) < towupper(c2); }
    static int compare(const wchar_t* s1, const wchar_t* s2, size_t n) {
        while (n-- != 0) {
            if (toupper(*s1) < toupper(*s2)) return -1;
            if (toupper(*s1) > toupper(*s2)) return 1;
            ++s1; ++s2;
        }
        return 0;
    }
    static const wchar_t* find(const wchar_t* s, int n, wchar_t a) {
        while (n-- > 0 && towupper(*s) != towupper(a)) {
            ++s;
        }
        return s;
    }
};

// Define type alias.
using ci_wstring_view = std::basic_string_view<wchar_t, ci_wchar_traits>;

// Use type alias.
if (ci_wstring_view const baseModuleName{dte->BaseDllName.Buffer, dte->BaseDllName.Length / sizeof(wchar_t)};
    !moduleName.empty() && baseModuleName.compare(moduleName.data()) != 0)
    continue;

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

I quite like that solution. If you are interested in implementation I'd merge a PR? If not I can see when I get around to this 😊

from polyhook_2_0.

no-realm avatar no-realm commented on August 11, 2024

Sure, I can submit a PR.
But I am not sure where you want the char_trait to be located?
If you plan on using it somewhere else, then it would make sense to put it into a separate file (header).

from polyhook_2_0.

stevemk14ebr avatar stevemk14ebr commented on August 11, 2024

You can place this in Misc.hpp

from polyhook_2_0.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.