[Feature] Checks for Nullable strings (#6050)

* Allows null strings in createString method c#

* Adds nullable strings to JS and swift

* Changes js checks

* Fixes typo
This commit is contained in:
mustiikhalil
2020-07-27 19:57:50 +03:00
committed by GitHub
parent 5d052f4e55
commit f1025b2847
6 changed files with 70 additions and 12 deletions

View File

@@ -385,7 +385,8 @@ public struct FlatBufferBuilder {
/// Insets a string into the buffer using UTF8
/// - Parameter str: String to be serialized
/// - returns: The strings offset in the buffer
mutating public func create(string str: String) -> Offset<String> {
mutating public func create(string str: String?) -> Offset<String> {
guard let str = str else { return Offset() }
let len = str.utf8.count
notNested()
preAlign(len: len &+ 1, type: UOffset.self)
@@ -395,20 +396,13 @@ public struct FlatBufferBuilder {
return Offset(offset: _bb.size)
}
/// Insets a string into the buffer using UTF8
/// - Parameter str: String to be serialized
/// - returns: The strings offset in the buffer
mutating public func create(string str: String?) -> Offset<String> {
guard let str = str else { return Offset() }
return create(string: str)
}
/// Inserts a shared string to the buffer
///
/// The function checks the stringOffsetmap if it's seen a similar string before
/// - Parameter str: String to be serialized
/// - returns: The strings offset in the buffer
mutating public func createShared(string str: String) -> Offset<String> {
mutating public func createShared(string str: String?) -> Offset<String> {
guard let str = str else { return Offset() }
if let offset = stringOffsetMap[str] {
return offset
}