New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 911896 link

Starred by 7 users

Issue metadata

Status: Started
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

[base] Use char16_t and std::u16string for UTF-16 strings

Project Member Reported by jdoerrie@chromium.org, Dec 5

Issue description

This bug serves as a tracking bug for using char16_t and std::u16string for UTF-16 strings in Chrome. This has several benefits:

- We can drop our custom base::char16 and base::string16 in favor of the STL versions.
- This also allows us to remove the custom character type traits we have for base::char16, reducing maintenance burden.
- It will allow us to replace ASCIIToUTF16("foobar") with u"foobar" to create literal UTF-16 strings, leading to more efficient and concise code.

In order to do this change, we will [2]:

* ensure we use wstring/wchar_t as little as possible (hopefully mostly done)
* reintroduce all the WideToUTF16/UTF16ToWide machinery that got removed (maybe the necessary places can be found locally by changing the string16 typedef away from wstring)
* switch string16 to be a typedef to u16string
* convert ASCIIToUTF16("") to u""
* convert the typenames everywhere and remove the typedef

Links to further discussions:
[1] https://groups.google.com/a/chromium.org/d/msg/blink-dev/gcoUbcjfsII/pdb-lqbTkm4J
[2] https://groups.google.com/a/chromium.org/d/msg/cxx/MrXsU4exAYw/JK6_S6a7BgAJ
 
This is a dupe of issue 23581, right?
Or should be blocked on it?
It's not really a dupe, as they have different goals. https://crbug.com/23581 aims to minimize std::wstring usage in shared code, while a result of this fixing this issue is that std::wstring and base::string16 are different types on all platforms.

Given that base::string16 and std::wstring are different on ~all non-Windows platforms, we should already be in a state where std::wstring usage is minimised in shared code. Thus technically the two bugs are neither dupes nor blocked on each other, as they can happily co-exist.

https://crbug.com/23581 addresses current std::wstring usage in shared code, while this bug addresses base::string16 usage in general. This will actually lead to replacing base::string16 with std::wstring in Windows specific code, as base::string16 my_str = L"FooBar"; will no longer compile. Lastly, this will probably lead to re-introducing some of the machinery we removed for issue 23581, such as base::ASCIIToWide: https://crrev.com/768973003. We might could do without, which is why I will leave a comment on the cxx@ thread and see what the overall opinion regarding this is.
Project Member

Comment 4 by bugdroid1@chromium.org, Dec 10

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/90636fa51343eedce0f09a1e3b6501f15d57c98a

commit 90636fa51343eedce0f09a1e3b6501f15d57c98a
Author: jdoerrie <jdoerrie@chromium.org>
Date: Mon Dec 10 11:09:54 2018

[base] Generalize Wide UTF Conversions

This change generalizes some of the std::wstring conversion functions to
work in a world where std::wstring and base::string16 are different
types.

Bug: 911896
Change-Id: I174cfb91141d7c26a2ca4ad812907192d77fc4af
Reviewed-on: https://chromium-review.googlesource.com/c/1368648
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615084}
[modify] https://crrev.com/90636fa51343eedce0f09a1e3b6501f15d57c98a/base/strings/utf_string_conversions.cc

Cc: scottmg@chromium.org groby@chromium.org a...@chromium.org pkasting@chromium.org richardsmith@google.com
 Issue 732026  has been merged into this issue.
Project Member

Comment 6 by bugdroid1@chromium.org, Dec 17

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/413d76ba15add315a2dabf5fe3ba8c3a92b3243d

commit 413d76ba15add315a2dabf5fe3ba8c3a92b3243d
Author: jdoerrie <jdoerrie@chromium.org>
Date: Mon Dec 17 13:08:53 2018

[base] Add Optimized Conversions between Wide and UTF16

These change adds optimized conversion functions between Wide and UTF16
that simply cast their arguments if possible. As currently WStringPiece
and StringPiece16 are the exact same type when base::char16 is wchar_t,
these functions will only become useful once base::char16 ischanged to
be char16_t on all platforms.

Bug: 911896
Change-Id: I9b2568b186fd3e5b8b7fa8b8718339cb0ff2c92b
Reviewed-on: https://chromium-review.googlesource.com/c/1373814
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#617101}
[modify] https://crrev.com/413d76ba15add315a2dabf5fe3ba8c3a92b3243d/base/strings/string_util.cc
[modify] https://crrev.com/413d76ba15add315a2dabf5fe3ba8c3a92b3243d/base/strings/string_util.h
[modify] https://crrev.com/413d76ba15add315a2dabf5fe3ba8c3a92b3243d/base/strings/utf_string_conversions.cc

Project Member

Comment 7 by bugdroid1@chromium.org, Dec 19

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/a177135a257c788ff19474b42550b1c610f7e2b5

commit a177135a257c788ff19474b42550b1c610f7e2b5
Author: jdoerrie <jdoerrie@chromium.org>
Date: Wed Dec 19 18:48:17 2018

[base] Introduce base::wdata() for WCHAR_T_IS_UTF16

This change introduces the base::wdata() utility function, granting
access to the underlying string buffer of UTF16 strings as a wchar_t*.

Bug: 911896
Change-Id: If8df399cbe446954bf11c37b3b22a01b7f87aca5
Reviewed-on: https://chromium-review.googlesource.com/c/1382073
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#617892}
[modify] https://crrev.com/a177135a257c788ff19474b42550b1c610f7e2b5/base/strings/string_util.cc
[modify] https://crrev.com/a177135a257c788ff19474b42550b1c610f7e2b5/base/strings/string_util.h
[modify] https://crrev.com/a177135a257c788ff19474b42550b1c610f7e2b5/base/strings/string_util_unittest.cc

Cc: vtsyrklevich@chromium.org
Project Member

Comment 9 by bugdroid1@chromium.org, Jan 16 (6 days ago)

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fb29b92c43f78a7e72b81789a248320a83676b81

commit fb29b92c43f78a7e72b81789a248320a83676b81
Author: jdoerrie <jdoerrie@chromium.org>
Date: Wed Jan 16 22:30:07 2019

[base] Introduce STRING16_LITERAL Macro

This change introcudes a STRING16_LITERAL macro to simplify constructing
base::char16 literals on Windows. This macro is inspired by FILE_PATH_LITERAL,
which serves a similar purpose for file paths. This macro will aid in the
migration of base::string16 to std::u16string, and can be removed once this
migration is done.

Bug: 911896
Change-Id: I69a9b12b5e0c161f9028d796761ec9624cf49fa7
Reviewed-on: https://chromium-review.googlesource.com/c/1411915
Reviewed-by: kylechar <kylechar@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#623407}
[modify] https://crrev.com/fb29b92c43f78a7e72b81789a248320a83676b81/base/strings/string16.h
[modify] https://crrev.com/fb29b92c43f78a7e72b81789a248320a83676b81/base/strings/string16_unittest.cc

Sign in to add a comment