Giter Site home page Giter Site logo

Comments (6)

AmokHuginnsson avatar AmokHuginnsson commented on May 13, 2024

Can you explain what is the use of the proposed API function?

from replxx.

Milerius avatar Milerius commented on May 13, 2024

It's the equivalent of the exemple in cxx-api.cxx (hints.size()) to detect that only one hint's remain

from replxx.

AmokHuginnsson avatar AmokHuginnsson commented on May 13, 2024

cxx-api example has call hints.size() indeed, but this call is not using replxx API, it is client code only. You can already achieve the same effect with C API. To be honest I still do not understand what do you want to achieve. Client code knows how many hints there are and replxx code does not cache this information anywhere. And caching this information should be responsibility of client code anyway.

from replxx.

Milerius avatar Milerius commented on May 13, 2024

How can you get the hints.size using the c api :O ?

from replxx.

AmokHuginnsson avatar AmokHuginnsson commented on May 13, 2024

Please look at the code of the cxx-api example carefully.
The hints variable is defined locally, and populated locally in the for loop, hints.size() is just a lucky convenience given by std::vector<T> type. In C code one would have to use local variable to count hints.

Using c-api hintHook as an example:

void hintHook(char const* context, replxx_hints* lc, int* contextLen, ReplxxColor* c, void* ud) {
  char** examples = (char**)( ud );
  int i;
  int utf8ContextLen = context_len( context );
  int prefixLen = strlen( context ) - utf8ContextLen;
  int hintCount = 0;
  *contextLen = utf8str_codepoint_len( context + prefixLen, utf8ContextLen );
  if ( *contextLen > 0 ) {
    for (i = 0; examples[i] != NULL; ++i) {                                                                                                                                                                                                                    
      if (strncmp(context + prefixLen, examples[i], utf8ContextLen) == 0) {
        replxx_add_hint(lc, examples[i]);
        ++ hintCount;
      }
    }
  }
  // now `hintCount` variable holds the number of hints.
} 

from replxx.

Milerius avatar Milerius commented on May 13, 2024

Ok I got it, thank's a lot

from replxx.

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.