# juce\_CharPointer\_UTF16.h!

**URL:** <https://forum.juce.com/t/juce-charpointer-utf16-h/6293>\
**Category:** Windows\
**Created:** [January 27, 2011, 3:51pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293 "2011-01-27T15:51:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 27, 2011, 3:51pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/1 "2011-01-27T15:51:28Z")

</div>

These new classes look great! But if juce\_wchar is a 16-bit value (under Windows only I believe) then functions like

```auto
juce_wchar CharPointer_UTF16::operator*() const throw();
```

will incorrectly decode Unicode code points that decode to values greater than 0xffff. Unless this is just a transition on the way to a final API, Windows is going to get the “short” end of the stick. Unless you set juce\_wchar to uint32 somewhere in a header I didn’t see.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 27, 2011, 3:56pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/2 "2011-01-27T15:56:29Z")

</div>

Please ignore these classes for the moment, I’m still working on them.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 27, 2011, 4:57pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/3 "2011-01-27T16:57:45Z")

</div>

This no longer compiles:

```auto
String s((unsigned long)0);
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 27, 2011, 5:11pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/4 "2011-01-27T17:11:22Z")

</div>

Yes, that constructor will have to disappear.

Because Android has a wchar\_t of 1 byte, and Windows has a wchar\_t of 2 bytes, I’m having to create a custom juce\_wchar which on those platforms is a typedef of an unsigned int. So any overloads that might cause confusion between a real unsigned int and a juce\_wchar will have to be removed.

It shouldn’t be a big deal - just cast your value to an int or int64 instead.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 27, 2011, 5:29pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/5 "2011-01-27T17:29:07Z")

</div>

> [@jules](#):
>
> I’m having to create a custom juce\_wchar which on those platforms is a typedef of an unsigned int.

[size=150]HOORAY!!![/size]

> [@](#):
>
> It shouldn’t be a big deal - just cast your value to an int or int64 instead.

I agree, it’s not a big deal. And since you don’t seem to mind extra typing in exchange for clarity, let me recommend:

```auto
template<class IntegralType>
static String String::fromInteger (IntegralType value) { /*...*/ }
```

to avoid seeing a bunch of casts that might not be so easy to search for.

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [January 27, 2011, 6:13pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/6 "2011-01-27T18:13:40Z")

</div>

I’m excited that Android was mentioned… 🙂

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 27, 2011, 7:30pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/7 "2011-01-27T19:30:18Z")

</div>

> [@cpr](#):
>
> I’m excited that Android was mentioned… 🙂

Yeah seriously…

[size=150]DROID!!![/size]

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 27, 2011, 9:34pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/8 "2011-01-27T21:34:21Z")

</div>

Jules:

1. Can I start banging on String with the new changes

2. What’s the recommended way to store strings as utf-8?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 27, 2011, 11:03pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/9 "2011-01-27T23:03:00Z")

</div>

1. …yeah, but please don’t hassle me with bugs or comments, I’m still stabilising it.
2. you could use a CharPointer\_UTF8 to wrap some storage of your own. I’ll probably create a wrapper class to make that easier, but haven’t done so yet.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 27, 2011, 11:30pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/10 "2011-01-27T23:30:14Z")

</div>

Okay…so what will String be? Always juce\_wchar, therefore always utf-32? Or will it be like before utf-16 on Windows, utf-32 everywhere else?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 28, 2011, 12:09pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/11 "2011-01-28T12:09:57Z")

</div>

> [@](#):
>
> Okay…so what will String be? Always juce\_wchar, therefore always utf-32? Or will it be like before utf-16 on Windows, utf-32 everywhere else?

Probably the same on all platforms, and will most likely default to utf32, but as I said, I’m still tinkering with this and thinking about it. If the O(N) random-access time isn’t a problem, I might make it all utf-8 instead.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 28, 2011, 12:59pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/12 "2011-01-28T12:59:23Z")

</div>

> [@jules](#):
>
> Probably the same on all platforms, and will most likely default to utf32, but as I said, I’m still tinkering with this and thinking about it. If the O(N) random-access time isn’t a problem, I might make it all utf-8 instead.

I have literally hundreds of thousands of strings to millions of strings in my in-memory database so I will be storing them as utf-8 no matter what. I’m fine with however Juce will represent strings for Components and elsewhere (file paths, plugin API, etc). As long as Juce provides conversions between encodings (which it seems you already do), I don’t mind performing a conversion at display time or at a point of call.

TextEditor looks to be the most affected by removal of array based indexing into String.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 28, 2011, 3:11pm UTC](https://forum.juce.com/t/juce-charpointer-utf16-h/6293/13 "2011-01-28T15:11:23Z")

</div>

I’ll probably provide a really simple templated string holder object for stuff like that, e.g. “StringBuffer\<CharPointer\_UTF8\>” that can be read and written with Strings.
