Re: Questions on conversions between char* to unsigned char* and vice versa

Discussion in 'C Programming' started by Navaneeth, Jan 4, 2011.

  1. Navaneeth

    Navaneeth Guest

    Hello Ben,

    I have very few functions that operates on UTF8 encoded strings. They are functions like, substr, length etc. Since the conversion from char* to unsigned char* is safe, I am wondering is it a best practice to convert to unsigned char* just before doing the UTF8 processing? So the conversion will happen when calling any of these routines.

    This way I can avoid changing other parts of the program and they can continue using char*. Whenever they need to process on UTF8, convert it to unsigned char*.

    Is that a fair idea?
     
    Navaneeth, Jan 4, 2011
    #1
    1. Advertising

  2. Navaneeth <> writes:

    > Hello Ben,


    You probably mean me. It's best, though, to address a post to the
    group. It would be foolhardy to solicit only my opinion!

    > I have very few functions that operates on UTF8 encoded strings. They
    > are functions like, substr, length etc. Since the conversion from
    > char* to unsigned char* is safe, I am wondering is it a best practice
    > to convert to unsigned char* just before doing the UTF8 processing? So
    > the conversion will happen when calling any of these routines.
    >
    > This way I can avoid changing other parts of the program and they can
    > continue using char*. Whenever they need to process on UTF8, convert
    > it to unsigned char*.
    >
    > Is that a fair idea?


    I don't find that particularly clear. I think you are saying that you
    intend to give your functions prototypes that use char * and to convert
    to unsigned char * "internally":

    size_t utf8str_length(const char *s);

    and so on. If so, I agree that this is a good plan. String data should
    usually be represented as a char array. If there are reasons to prefer
    to manipulate it as unsigned chars then you can do that at the point
    when that preference becomes important.

    --
    Ben.
     
    Ben Bacarisse, Jan 4, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim  Wong
    Replies:
    5
    Views:
    21,962
    Tim Wong
    Jan 21, 2005
  2. Replies:
    3
    Views:
    8,817
  3. Navaneeth
    Replies:
    8
    Views:
    695
    Keith Thompson
    Jan 1, 2011
  4. Navaneeth
    Replies:
    3
    Views:
    330
    Seebs
    Jan 1, 2011
  5. Navaneeth
    Replies:
    3
    Views:
    335
    Thad Smith
    Jan 5, 2011
Loading...

Share This Page