Swift 里字符串(九)UTF16View
即以 UTF16 编码的格式来查看字符串。
UTF16View 是一个结构体
@_fixed_layout
public struct UTF16View {
@usableFromInline
internal var _guts: _StringGuts
@inlinable
internal init(_ guts: _StringGuts) {
self._guts = guts
_invariantCheck()
}
}
UTF16View 遵守 BidirectionalCollection 协议
可以正向/反向遍历,核心代码如下:
@inlinable @inline(__always)
public func index(after i: Index) -> Index {
if _slowPath(_guts.isForeign) { return _foreignIndex(after: i) }
if _guts.isASCII { return i.nextEncoded }
// For a BMP scalar (1-3 UTF-8 code units), advance past it. For a non-BMP
// scalar, use a transcoded offset first.
let len = _guts.fastUTF8ScalarLength(startingAt: i.encodedOffset)
if len == 4 && i.transcodedOffset == 0 {
return i.nextTranscoded
}
return i.strippingTranscoding.encoded(offsetBy: len)
}
读写String 的 utf16属性
public var utf16: UTF16View {
@inline(__always) get { return UTF16View(_guts) }
@inline(__always) set { self = String(newValue._guts) }
}
每次读,都会生成一个新的UTF16View。
每次写,都会更新String内部的_guts。
UTF8View 属性
和UTF16View类似,也是一个结构体,也遵守BidirectionalCollection协议。
public var utf8: UTF8View {
@inline(__always) get { return UTF8View(self._guts) }
set { self = String(newValue._guts) }
}
Swift 里字符串(九)UTF16View的更多相关文章
- Swift 里字符串(十)修改字符串
以append操作为例 public mutating func append(_ other: String) { if self.isEmpty && !_guts.hasNati ...
- Swift里字符串(五)Native strings
Native strings have tail-allocated storage, which begins at an offset of nativeBias from the storage ...
- Swift 里字符串(七)stringIndex
在 String 里,用来索引 Character 的,不是整数,而是StringIndex 内部结构 extension String { /// A position of a character ...
- Swift里字符串(六)Shared strings
Shared strings do not have tail-allocated storage, but can provide access upon query to contiguous U ...
- Swift 里字符串(三)small String
 small string, 只有两个 UInt64 的字,这里面存储了所有的信息. 内存布局如下:  第二个 UInt64 存储了标记位和长度信息,以及部分字符串的值 // Get an int ...
- Swift 里字符串(四)large sting
对于普通的字符串,对应的_StringObject 有两个存储属性: _countAndFlagsBits: UInt64 _object: Builtin.BridgeObject _countAn ...
- Swift 里字符串(一)概览
感受一下字符串相关的源文件个数  String 概览 是一个结构体 只有一个变量,类型是 _StringGuts  如上所示,String 真正的内容在__StringStorage或者__Sha ...
- Swift 里字符串(八)UnicodeScalarView
即以 Unicode Scarlar 的方式来查看字符串. /// let flag = "
- Swift 里字符串(十一)OC 字符串和 Swift 字符串的转换
 to OC func _bridgeToObjectiveCImpl() -> AnyObject { if _guts.isSmall { return _guts.asSmall.wit ...
随机推荐
- Windows操作系统下SVN无法上传*.o文件
Windows操作系统下SVN无法上传*.o文件 2017年09月07日 10:14:49 yanlaifan 阅读数:834 摘自:https://blog.csdn.net/yanlaifan/ ...
- qrc转换成py
- c++中如何定义编译期间常量,即这个常量可以用于定义数组下标
在c++中,类里面的成员变量不仅仅可以被const修饰,还可以被static const修饰,此时一个内建类型(如int ,char ,long等)的static const 可以看做是一个编译期间的 ...
- 让QQ好友现形
方法一 现在使用QQ的朋友,越来越注重保护自己的个人信息,如果对方将个人资料设置为保密你就无法看到对方的资料了,而这位好友如果又有着不断变换昵称的不良习惯,那么随着QQ好友名单的不断增加,时间一长,你 ...
- ESP8266-01一些内容
系统有些指令必须特性状态下才可以执行,即先执行一些其它AT指令 1.设置station模式的IP信息 AT+CIPSTA="192.168.19.1","192.168. ...
- Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut aaa
这个错误是说,找不到这个注释: 解决方案: 1.更改自己本机的jdk版本(我的更改了无效): 在工程选择框内点击右键--->build path----->Library--->ad ...
- 百度上传插件 WebUploader初始使用
引入资源 使用Web Uploader文件上传需要引入三种资源:JS, CSS, SWF. <!--引入CSS--> <link rel="stylesheet" ...
- 设置p标签可编辑
一,只可编辑,粘贴复制字段长度不正常 <p contenteditable="true" >这是一个可编辑内容的p标签啦啦~</p> 二,可编辑,可粘贴复制 ...
- HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏
Deleting Edges Time ...
- follow me
IM InfoSphere Information Server for Data Integration Fundamentals Bootcamp 7月15日 5 北京 IM InfoSphere ...