Jump to content


New api improvement


  • Please log in to reply
No replies to this topic

#1 armin.orlik

armin.orlik

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 22 November 2018 - 09:59 AM

Hello,
We have small a small api improvement suggestion - Thank you Konrad Krawczuk from Viking Potatoes!

In strbuf.h there are methods to access text data like this:
    char *  Text() const
    { return buffer; }
    char *  Value() const
    { return buffer; }
    unsigned char *UText() const
    { return (unsigned char *)Text(); }
    char *  End() const
    { return Text() + length; }
    unsigned char *UEnd() const
    { return UText() + length; }
This is pretty inconsistent with const-correctness of the objects. It allows to
modify buffer on const StrPtr. It would be more convinient to replace them to:
    const char *    Text() const
    { return buffer; }
    const char *    Value() const
    { return buffer; }
    const unsigned char *UText() const
    { return (unsigned char *)Text(); }
    const char *    End() const
    { return Text() + length; }
    const unsigned char *UEnd() const
    { return UText() + length; }
  
It also helps for better type deduction when dealing with templates and function overloads.
Like taking const char* specialization is not taken when other one are generic.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users