You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some Azure services return substring offset & length values within a string. For example, the offset & length within a string to a name, email address, or phone #.
521
+
Some Azure services return substring offset & length values within a string. For example, the offset & length within a string to a name, email address, or phone number.
521
522
When a service response includes a string, the client's programming language deserializes that string into that language's internal string encoding. Below are the possible encodings and examples of languages that use each encoding:
522
523
523
524
| Encoding | Example languages |
@@ -526,44 +527,44 @@ When a service response includes a string, the client's programming language des
526
527
| UTF-16 | JavaScript, Java, C# |
527
528
| CodePoint (UTF-32) | Python |
528
529
529
-
Because the service doesn't know what language a client is written in and what string encoding that language uses, the service can't return UTF-agnostic offset and length values that the client can use to index within the string. To address this, the service response must include offset & length values for all 3 possible encodings and then the client code must select the encoding it required by its language's internal string encoding.
530
+
Because the service doesn't know in what language a client is written and what string encoding that language uses, the service can't return UTF-agnostic offset and length values that the client can use to index within the string. To address this, the service response must include offset & length values for all 3 possible encodings and then the client code must select the encoding required by its language's internal string encoding.
530
531
531
532
For example, if a service response needed to identify offset & length values for "name" and "email" substrings, the JSON response would look like this:
532
533
533
-
```
534
+
```json
534
535
{
535
536
(... other properties not shown...)
536
537
"fullString": "(...some string containing a name and an email address...)",
537
538
"name": {
538
539
"offset": {
539
540
"utf8": 12,
540
541
"utf16": 10,
541
-
"codePoint": 4
542
+
"codePoint": 4
542
543
},
543
544
"length": {
544
545
"uft8": 10,
545
546
"utf16": 8,
546
-
"codePoint": 2
547
+
"codePoint": 2
547
548
}
548
549
},
549
550
"email": {
550
551
"offset": {
551
552
"utf8": 12,
552
553
"utf16": 10,
553
-
"codePoint": 4
554
+
"codePoint": 4
554
555
},
555
556
"length": {
556
557
"uft8": 10,
557
558
"utf16": 8,
558
-
"codePoint": 4
559
+
"codePoint": 4
559
560
}
560
561
}
561
562
}
562
563
```
563
564
564
565
Then, the Go developer, for example, would get the substring containing the name using code like this:
Copy file name to clipboardExpand all lines: azure/Guidelines.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1107,6 +1107,14 @@ When a service response includes a string offset or length value, it should spec
1107
1107
1108
1108
<ahref="#substrings-return-value-for-each-encoding"name="substrings-return-value-for-each-encoding">:white_check_mark:</a> **DO** include all 3 encodings (UTF-8, UTF-16, and CodePoint) for every string offset or length value in a service response.
1109
1109
1110
+
<ahref="#substrings-return-value-structure"name="substrings-return-value-structure">:white_check_mark:</a> **DO** define every string offset or length value in a service response as an object with the following structure:
|`utf8`| integer | true | The offset or length of the substring in UTF-8 encoding |
1115
+
|`utf16`| integer | true | The offset or length of the substring in UTF-16 encoding |
1116
+
|`codePoint`| integer | true | The offset or length of the substring in CodePoint encoding |
1117
+
1110
1118
<ahref="#telemetry"name="telemetry"></a>
1111
1119
### Distributed Tracing & Telemetry
1112
1120
Azure SDK client guidelines specify that client libraries must send telemetry data through the `User-Agent` header, `X-MS-UserAgent` header, and Open Telemetry.
0 commit comments