libmongocrypt-helper 1.7.4.0.1001 → 1.8.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (398) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/extconf.rb +2 -2
  4. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  5. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  6. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  7. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  8. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  17. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  62. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  63. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  64. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  65. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  66. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  67. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  71. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  75. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  79. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  80. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  143. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  194. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  196. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  198. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  199. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  314. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  315. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  316. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  318. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  370. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  371. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  373. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  374. data/lib/libmongocrypt_helper/version.rb +2 -2
  375. data/lib/libmongocrypt_helper.rb +2 -2
  376. data.tar.gz.sig +0 -0
  377. metadata +154 -26
  378. metadata.gz.sig +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  380. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  381. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  382. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  383. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  384. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  392. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  393. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  394. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  397. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  398. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -1,17 +1,17 @@
1
1
  #ifndef MONGOCRYPT_STR_PRIVATE_H
2
2
  #define MONGOCRYPT_STR_PRIVATE_H
3
3
 
4
- #include "./user-check.h"
5
4
  #include "./macros.h"
5
+ #include "./user-check.h"
6
6
 
7
- #include <stdlib.h>
8
- #include <string.h>
9
7
  #include <assert.h>
10
- #include <stddef.h>
11
- #include <stdio.h>
12
8
  #include <inttypes.h>
13
9
  #include <limits.h> /* INT_MAX */
14
10
  #include <stdbool.h>
11
+ #include <stddef.h>
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
15
 
16
16
  #if defined(MLIB_HAVE_STRINGS_H)
17
17
  #include <strings.h> /* For strncasecmp. */
@@ -31,18 +31,18 @@ MLIB_C_LINKAGE_BEGIN
31
31
  * @ref mstr object, OR returned from @ref mstrv_view_cstr.
32
32
  */
33
33
  typedef struct mstr_view {
34
- /**
35
- * @brief Pointer to the beginning of the code unit array.
36
- *
37
- * @note DO NOT MODIFY
38
- */
39
- const char *data;
40
- /**
41
- * @brief Length of the pointed-to code unit array
42
- *
43
- * @note DO NOT MODIFY
44
- */
45
- size_t len;
34
+ /**
35
+ * @brief Pointer to the beginning of the code unit array.
36
+ *
37
+ * @note DO NOT MODIFY
38
+ */
39
+ const char *data;
40
+ /**
41
+ * @brief Length of the pointed-to code unit array
42
+ *
43
+ * @note DO NOT MODIFY
44
+ */
45
+ size_t len;
46
46
  } mstr_view;
47
47
 
48
48
  /**
@@ -71,26 +71,27 @@ typedef struct mstr_view {
71
71
  * Passing or returning an `mstr_view` is non-owning.
72
72
  */
73
73
  typedef struct mstr {
74
- union {
75
- struct {
76
- /**
77
- * @brief Pointer to the beginning of the code unit array.
78
- *
79
- * @note DO NOT MODIFY
80
- */
81
- const char *data;
82
- /**
83
- * @brief Length of the pointed-to code unit array
84
- *
85
- * @note DO NOT MODIFY
86
- */
87
- size_t len;
88
- };
89
- /**
90
- * @brief A non-owning `mstr_view` of the string
91
- */
92
- mstr_view view;
93
- };
74
+ union {
75
+ struct {
76
+ /**
77
+ * @brief Pointer to the beginning of the code unit array.
78
+ *
79
+ * @note DO NOT MODIFY
80
+ */
81
+ const char *data;
82
+ /**
83
+ * @brief Length of the pointed-to code unit array
84
+ *
85
+ * @note DO NOT MODIFY
86
+ */
87
+ size_t len;
88
+ };
89
+
90
+ /**
91
+ * @brief A non-owning `mstr_view` of the string
92
+ */
93
+ mstr_view view;
94
+ };
94
95
  } mstr;
95
96
 
96
97
  /**
@@ -100,42 +101,42 @@ typedef struct mstr {
100
101
  * be used as an @ref mstr by accessing the @ref mstr_mut::mstr member.
101
102
  */
102
103
  typedef struct mstr_mut {
103
- union {
104
- struct {
105
- /**
106
- * @brief Pointer to the beginning of the mutable code unit array.
107
- *
108
- * @note DO NOT MODIFY THE POINTER VALUE. Only modify the pointed-to
109
- * characters.
110
- */
111
- char *data;
112
- /**
113
- * @brief Length of the pointed-to code unit array.
114
- *
115
- * @note DO NOT MODIFY
116
- */
117
- size_t len;
118
- };
119
- /// Convert the mutable string to an immutable string
120
- struct mstr mstr;
121
- /// Convert the mutable string to an immutable string view
122
- mstr_view view;
123
- };
104
+ union {
105
+ struct {
106
+ /**
107
+ * @brief Pointer to the beginning of the mutable code unit array.
108
+ *
109
+ * @note DO NOT MODIFY THE POINTER VALUE. Only modify the pointed-to
110
+ * characters.
111
+ */
112
+ char *data;
113
+ /**
114
+ * @brief Length of the pointed-to code unit array.
115
+ *
116
+ * @note DO NOT MODIFY
117
+ */
118
+ size_t len;
119
+ };
120
+ /// Convert the mutable string to an immutable string
121
+ struct mstr mstr;
122
+ /// Convert the mutable string to an immutable string view
123
+ mstr_view view;
124
+ };
124
125
  } mstr_mut;
125
126
 
126
127
  /**
127
128
  * @brief A null @ref mstr
128
129
  */
129
- #define MSTR_NULL (MLIB_INIT (mstr){{{NULL, 0}}})
130
+ #define MSTR_NULL (MLIB_INIT(mstr){{{NULL, 0}}})
130
131
  /**
131
132
  * @brief A null @ref mstr_view
132
133
  */
133
- #define MSTRV_NULL (MLIB_INIT (mstr_view){NULL, 0})
134
+ #define MSTRV_NULL (MLIB_INIT(mstr_view){NULL, 0})
134
135
 
135
136
  /**
136
137
  * @brief Create an @ref mstr_view that views the given string literal
137
138
  */
138
- #define mstrv_lit(String) (mstrv_view_data (String "", (sizeof String) - 1))
139
+ #define mstrv_lit(String) (mstrv_view_data(String "", (sizeof String) - 1))
139
140
 
140
141
  /**
141
142
  * @brief Create a new mutable code-unit array of the given length,
@@ -149,16 +150,14 @@ typedef struct mstr_mut {
149
150
  * @note The @ref mstr_mut::mstr member MUST eventually be given to
150
151
  * @ref mstr_free().
151
152
  */
152
- static inline mstr_mut
153
- mstr_new (size_t len)
154
- {
153
+ static inline mstr_mut mstr_new(size_t len) {
155
154
  #ifndef __clang_analyzer__
156
- assert (len < SIZE_MAX);
157
- return MLIB_INIT (mstr_mut){{{(char *) calloc (1, len + 1), len}}};
155
+ assert(len < SIZE_MAX);
156
+ return MLIB_INIT(mstr_mut){{{(char *)calloc(1, len + 1), len}}};
158
157
  #else
159
- // Clang-analyzer is smart enough to see the calloc(), but not smart enough
160
- // to link it to the free() in mstr_free()
161
- return MLIB_INIT (mstr_mut){};
158
+ // Clang-analyzer is smart enough to see the calloc(), but not smart enough
159
+ // to link it to the free() in mstr_free()
160
+ return MLIB_INIT(mstr_mut){};
162
161
  #endif
163
162
  }
164
163
 
@@ -169,10 +168,8 @@ mstr_new (size_t len)
169
168
  * @param len The length of the character array, in code units
170
169
  * @return mstr_view A non-owning string.
171
170
  */
172
- static inline mstr_view
173
- mstrv_view_data (const char *s, size_t len)
174
- {
175
- return MLIB_INIT (mstr_view){s, len};
171
+ static inline mstr_view mstrv_view_data(const char *s, size_t len) {
172
+ return MLIB_INIT(mstr_view){s, len};
176
173
  }
177
174
 
178
175
  /**
@@ -182,10 +179,8 @@ mstrv_view_data (const char *s, size_t len)
182
179
  * @param s A pointer to a null-terminated character array
183
180
  * @return mstr_view A view of the pointed-to string
184
181
  */
185
- static inline mstr_view
186
- mstrv_view_cstr (const char *s)
187
- {
188
- return mstrv_view_data (s, strlen (s));
182
+ static inline mstr_view mstrv_view_cstr(const char *s) {
183
+ return mstrv_view_data(s, strlen(s));
189
184
  }
190
185
 
191
186
  /**
@@ -198,12 +193,10 @@ mstrv_view_cstr (const char *s)
198
193
  *
199
194
  * @note The resulting string will be null-terminated.
200
195
  */
201
- static inline mstr
202
- mstr_copy_data (const char *s, size_t len)
203
- {
204
- mstr_mut r = mstr_new (len);
205
- memcpy (r.data, s, len);
206
- return r.mstr;
196
+ static inline mstr mstr_copy_data(const char *s, size_t len) {
197
+ mstr_mut r = mstr_new(len);
198
+ memcpy(r.data, s, len);
199
+ return r.mstr;
207
200
  }
208
201
 
209
202
  /**
@@ -212,10 +205,8 @@ mstr_copy_data (const char *s, size_t len)
212
205
  * @param s A pointer to a null-terminated character array
213
206
  * @return mstr A new string copied from the pointed-to string
214
207
  */
215
- static inline mstr
216
- mstr_copy_cstr (const char *s)
217
- {
218
- return mstr_copy_data (s, strlen (s));
208
+ static inline mstr mstr_copy_cstr(const char *s) {
209
+ return mstr_copy_data(s, strlen(s));
219
210
  }
220
211
 
221
212
  /**
@@ -224,10 +215,8 @@ mstr_copy_cstr (const char *s)
224
215
  * @param s A string view to copy from
225
216
  * @return mstr A new string copied from the given view
226
217
  */
227
- static inline mstr
228
- mstr_copy (mstr_view s)
229
- {
230
- return mstr_copy_data (s.data, s.len);
218
+ static inline mstr mstr_copy(mstr_view s) {
219
+ return mstr_copy_data(s.data, s.len);
231
220
  }
232
221
 
233
222
  /**
@@ -235,10 +224,8 @@ mstr_copy (mstr_view s)
235
224
  *
236
225
  * @param s The string to free
237
226
  */
238
- static inline void
239
- mstr_free (mstr s)
240
- {
241
- free ((char *) s.data);
227
+ static inline void mstr_free(mstr s) {
228
+ free((char *)s.data);
242
229
  }
243
230
 
244
231
  /**
@@ -248,24 +235,22 @@ mstr_free (mstr s)
248
235
  * @param s The @ref mstr_mut to update
249
236
  * @param new_len The new length of the string
250
237
  */
251
- static inline void
252
- mstrm_resize (mstr_mut *s, size_t new_len)
253
- {
254
- if (new_len <= s->len) {
255
- s->len = new_len;
256
- } else {
257
- const size_t old_len = s->len;
238
+ static inline void mstrm_resize(mstr_mut *s, size_t new_len) {
239
+ if (new_len <= s->len) {
240
+ s->len = new_len;
241
+ } else {
242
+ const size_t old_len = s->len;
258
243
  #ifndef __clang_analyzer__
259
- // Clang-analyzer is smart enough to see the calloc(), but not smart
260
- // enough to link it to the free() in mstr_free()
261
- assert (new_len < SIZE_MAX);
262
- s->data = (char *) realloc ((char *) s->data, new_len + 1);
244
+ // Clang-analyzer is smart enough to see the calloc(), but not smart
245
+ // enough to link it to the free() in mstr_free()
246
+ assert(new_len < SIZE_MAX);
247
+ s->data = (char *)realloc((char *)s->data, new_len + 1);
263
248
  #endif
264
- s->len = new_len;
265
- assert (new_len >= old_len);
266
- memset (s->data + old_len, 0, new_len - old_len);
267
- }
268
- s->data[new_len] = (char) 0;
249
+ s->len = new_len;
250
+ assert(new_len >= old_len);
251
+ memset(s->data + old_len, 0, new_len - old_len);
252
+ }
253
+ s->data[new_len] = (char)0;
269
254
  }
270
255
 
271
256
  /**
@@ -294,11 +279,9 @@ mstrm_resize (mstr_mut *s, size_t new_len)
294
279
  * mstr_assign(&s, convert_to_uppercase(s.view));
295
280
  * ```
296
281
  */
297
- static inline void
298
- mstr_assign (mstr *s, mstr from)
299
- {
300
- mstr_free (*s);
301
- *s = from;
282
+ static inline void mstr_assign(mstr *s, mstr from) {
283
+ mstr_free(*s);
284
+ *s = from;
302
285
  }
303
286
 
304
287
  /**
@@ -310,31 +293,28 @@ mstr_assign (mstr *s, mstr from)
310
293
  * @return int The zero-based index of the first instance of `needle` in
311
294
  * `given`, or -1 if no substring is found.
312
295
  */
313
- static inline int
314
- mstr_find (mstr_view given, mstr_view needle)
315
- {
316
- const char *const scan_end = given.data + given.len;
317
- const char *const needle_end = needle.data + needle.len;
318
- for (const char *scan = given.data; scan != scan_end; ++scan) {
319
- size_t remain = (size_t) (scan_end - scan);
320
- if (remain < needle.len) {
321
- break;
322
- }
323
- const char *subscan = scan;
324
- for (const char *nscan = needle.data; nscan != needle_end;
325
- ++nscan, ++subscan) {
326
- if (*nscan == *subscan) {
327
- continue;
328
- } else {
329
- goto skip;
330
- }
331
- }
332
- // Got through the whole loop of scanning the needle
333
- return (int) (scan - given.data);
334
- skip:
335
- (void) 0;
336
- }
337
- return -1;
296
+ static inline int mstr_find(mstr_view given, mstr_view needle) {
297
+ const char *const scan_end = given.data + given.len;
298
+ const char *const needle_end = needle.data + needle.len;
299
+ for (const char *scan = given.data; scan != scan_end; ++scan) {
300
+ size_t remain = (size_t)(scan_end - scan);
301
+ if (remain < needle.len) {
302
+ break;
303
+ }
304
+ const char *subscan = scan;
305
+ for (const char *nscan = needle.data; nscan != needle_end; ++nscan, ++subscan) {
306
+ if (*nscan == *subscan) {
307
+ continue;
308
+ } else {
309
+ goto skip;
310
+ }
311
+ }
312
+ // Got through the whole loop of scanning the needle
313
+ return (int)(scan - given.data);
314
+ skip:
315
+ (void)0;
316
+ }
317
+ return -1;
338
318
  }
339
319
 
340
320
  /**
@@ -346,30 +326,27 @@ mstr_find (mstr_view given, mstr_view needle)
346
326
  * @return int The zero-based index of the last instance of `needle` in
347
327
  * `given`, or -1 if no substring is found.
348
328
  */
349
- static inline int
350
- mstr_rfind (mstr_view given, mstr_view needle)
351
- {
352
- if (needle.len > given.len) {
353
- return -1;
354
- }
355
- const char *scan = given.data + given.len - needle.len;
356
- const char *const needle_end = needle.data + needle.len;
357
- for (; scan >= given.data; --scan) {
358
- const char *subscan = scan;
359
- for (const char *nscan = needle.data; nscan != needle_end;
360
- ++nscan, ++subscan) {
361
- if (*nscan == *subscan) {
362
- continue;
363
- } else {
364
- goto skip;
365
- }
366
- }
367
- // Got through the whole loop of scanning the needle
368
- return (int) (scan - given.data);
369
- skip:
370
- (void) 0;
371
- }
372
- return -1;
329
+ static inline int mstr_rfind(mstr_view given, mstr_view needle) {
330
+ if (needle.len > given.len) {
331
+ return -1;
332
+ }
333
+ const char *scan = given.data + given.len - needle.len;
334
+ const char *const needle_end = needle.data + needle.len;
335
+ for (; scan >= given.data; --scan) {
336
+ const char *subscan = scan;
337
+ for (const char *nscan = needle.data; nscan != needle_end; ++nscan, ++subscan) {
338
+ if (*nscan == *subscan) {
339
+ continue;
340
+ } else {
341
+ goto skip;
342
+ }
343
+ }
344
+ // Got through the whole loop of scanning the needle
345
+ return (int)(scan - given.data);
346
+ skip:
347
+ (void)0;
348
+ }
349
+ return -1;
373
350
  }
374
351
 
375
352
  /**
@@ -382,47 +359,41 @@ mstr_rfind (mstr_view given, mstr_view needle)
382
359
  * @param insert The string to insert at `at`.
383
360
  * @return mstr A new string that is the result of the splice
384
361
  */
385
- static inline mstr
386
- mstr_splice (mstr_view s, size_t at, size_t del_count, mstr_view insert)
387
- {
388
- assert (at <= s.len);
389
- const size_t remain = s.len - at;
390
- if (del_count > remain) {
391
- del_count = remain;
392
- }
393
- /* at this point, it is absolutely necessary that del_count <= s.len */
394
- assert (s.len - del_count <= SIZE_MAX - insert.len);
395
- const size_t new_size = s.len - del_count + insert.len;
396
- mstr_mut ret = mstr_new (new_size);
397
- char *p = ret.data;
398
- memcpy (p, s.data, at);
399
- p += at;
400
- if (insert.data) {
401
- memcpy (p, insert.data, insert.len);
402
- p += insert.len;
403
- }
404
- /* 'at <= s.len' was already asserted earlier */
405
- assert (s.len - at >= del_count);
406
- memcpy (p, s.data + at + del_count, s.len - at - del_count);
407
- return ret.mstr;
362
+ static inline mstr mstr_splice(mstr_view s, size_t at, size_t del_count, mstr_view insert) {
363
+ assert(at <= s.len);
364
+ const size_t remain = s.len - at;
365
+ if (del_count > remain) {
366
+ del_count = remain;
367
+ }
368
+ /* at this point, it is absolutely necessary that del_count <= s.len */
369
+ assert(s.len - del_count <= SIZE_MAX - insert.len);
370
+ const size_t new_size = s.len - del_count + insert.len;
371
+ mstr_mut ret = mstr_new(new_size);
372
+ char *p = ret.data;
373
+ memcpy(p, s.data, at);
374
+ p += at;
375
+ if (insert.data) {
376
+ memcpy(p, insert.data, insert.len);
377
+ p += insert.len;
378
+ }
379
+ /* 'at <= s.len' was already asserted earlier */
380
+ assert(s.len - at >= del_count);
381
+ memcpy(p, s.data + at + del_count, s.len - at - del_count);
382
+ return ret.mstr;
408
383
  }
409
384
 
410
385
  /**
411
386
  * @brief Append the given suffix to the given string
412
387
  */
413
- static inline mstr
414
- mstr_append (mstr_view s, mstr_view suffix)
415
- {
416
- return mstr_splice (s, s.len, 0, suffix);
388
+ static inline mstr mstr_append(mstr_view s, mstr_view suffix) {
389
+ return mstr_splice(s, s.len, 0, suffix);
417
390
  }
418
391
 
419
392
  /**
420
393
  * @brief Prepend the given prefix to the given string
421
394
  */
422
- static inline mstr
423
- mstr_prepend (mstr_view s, mstr_view prefix)
424
- {
425
- return mstr_splice (s, 0, 0, prefix);
395
+ static inline mstr mstr_prepend(mstr_view s, mstr_view prefix) {
396
+ return mstr_splice(s, 0, 0, prefix);
426
397
  }
427
398
 
428
399
  /**
@@ -433,10 +404,8 @@ mstr_prepend (mstr_view s, mstr_view prefix)
433
404
  * @param infix The string to insert into `s`
434
405
  * @return mstr A new string with `infix` inserted
435
406
  */
436
- static inline mstr
437
- mstr_insert (mstr_view s, size_t at, mstr_view infix)
438
- {
439
- return mstr_splice (s, at, 0, infix);
407
+ static inline mstr mstr_insert(mstr_view s, size_t at, mstr_view infix) {
408
+ return mstr_splice(s, at, 0, infix);
440
409
  }
441
410
 
442
411
  /**
@@ -447,29 +416,23 @@ mstr_insert (mstr_view s, size_t at, mstr_view infix)
447
416
  * @param count The number of characters to remove
448
417
  * @return mstr A new string with the deletion result.
449
418
  */
450
- static inline mstr
451
- mstr_erase (mstr_view s, size_t at, size_t count)
452
- {
453
- return mstr_splice (s, at, count, mstrv_view_cstr (""));
419
+ static inline mstr mstr_erase(mstr_view s, size_t at, size_t count) {
420
+ return mstr_splice(s, at, count, mstrv_view_cstr(""));
454
421
  }
455
422
 
456
423
  /**
457
424
  * @brief Erase `len` characters from the beginning of the string
458
425
  */
459
- static inline mstr
460
- mstr_remove_prefix (mstr_view s, size_t len)
461
- {
462
- return mstr_erase (s, 0, len);
426
+ static inline mstr mstr_remove_prefix(mstr_view s, size_t len) {
427
+ return mstr_erase(s, 0, len);
463
428
  }
464
429
 
465
430
  /**
466
431
  * @brief Erase `len` characters from the end of the string
467
432
  */
468
- static inline mstr
469
- mstr_remove_suffix (mstr_view s, size_t len)
470
- {
471
- assert (s.len >= len);
472
- return mstr_erase (s, s.len - len, len);
433
+ static inline mstr mstr_remove_suffix(mstr_view s, size_t len) {
434
+ assert(s.len >= len);
435
+ return mstr_erase(s, s.len - len, len);
473
436
  }
474
437
 
475
438
  /**
@@ -481,17 +444,15 @@ mstr_remove_suffix (mstr_view s, size_t len)
481
444
  * remaining length.
482
445
  * @return mstr A new string that is a substring of `s`
483
446
  */
484
- static inline mstr
485
- mstr_substr (mstr_view s, size_t at, size_t len)
486
- {
487
- assert (at <= s.len);
488
- const size_t remain = s.len - at;
489
- if (len > remain) {
490
- len = remain;
491
- }
492
- mstr_mut r = mstr_new (len);
493
- memcpy (r.data, s.data + at, len);
494
- return r.mstr;
447
+ static inline mstr mstr_substr(mstr_view s, size_t at, size_t len) {
448
+ assert(at <= s.len);
449
+ const size_t remain = s.len - at;
450
+ if (len > remain) {
451
+ len = remain;
452
+ }
453
+ mstr_mut r = mstr_new(len);
454
+ memcpy(r.data, s.data + at, len);
455
+ return r.mstr;
495
456
  }
496
457
 
497
458
  /**
@@ -503,36 +464,30 @@ mstr_substr (mstr_view s, size_t at, size_t len)
503
464
  * remaining length.
504
465
  * @return mstr_view A view of `s`.
505
466
  */
506
- static inline mstr_view
507
- mstrv_subview (mstr_view s, size_t at, size_t len)
508
- {
509
- assert (at <= s.len);
510
- const size_t remain = s.len - at;
511
- if (len > remain) {
512
- len = remain;
513
- }
514
- return mstrv_view_data (s.data + at, len);
467
+ static inline mstr_view mstrv_subview(mstr_view s, size_t at, size_t len) {
468
+ assert(at <= s.len);
469
+ const size_t remain = s.len - at;
470
+ if (len > remain) {
471
+ len = remain;
472
+ }
473
+ return mstrv_view_data(s.data + at, len);
515
474
  }
516
475
 
517
476
  /**
518
477
  * @brief Obtain a view of another string by removing `len` characters from the
519
478
  * front
520
479
  */
521
- static inline mstr_view
522
- mstrv_remove_prefix (mstr_view s, size_t len)
523
- {
524
- return mstrv_subview (s, len, s.len);
480
+ static inline mstr_view mstrv_remove_prefix(mstr_view s, size_t len) {
481
+ return mstrv_subview(s, len, s.len);
525
482
  }
526
483
 
527
484
  /**
528
485
  * @brief Obtain a view of another string by removing `len` characters from the
529
486
  * end.
530
487
  */
531
- static inline mstr_view
532
- mstrv_remove_suffix (mstr_view s, size_t len)
533
- {
534
- assert (s.len >= len);
535
- return mstrv_subview (s, 0, s.len - len);
488
+ static inline mstr_view mstrv_remove_suffix(mstr_view s, size_t len) {
489
+ assert(s.len >= len);
490
+ return mstrv_subview(s, 0, s.len - len);
536
491
  }
537
492
 
538
493
  /**
@@ -542,11 +497,9 @@ mstrv_remove_suffix (mstr_view s, size_t len)
542
497
  * @param new_len The new length of the string
543
498
  * @return mstr A new string copied from the beginning of `s`
544
499
  */
545
- static inline mstr
546
- mstr_trunc (mstr_view s, size_t new_len)
547
- {
548
- assert (new_len <= s.len);
549
- return mstr_remove_suffix (s, s.len - new_len);
500
+ static inline mstr mstr_trunc(mstr_view s, size_t new_len) {
501
+ assert(new_len <= s.len);
502
+ return mstr_remove_suffix(s, s.len - new_len);
550
503
  }
551
504
 
552
505
  /**
@@ -560,134 +513,113 @@ mstr_trunc (mstr_view s, size_t new_len)
560
513
  *
561
514
  * @note If `find` is empty, returns a copy of `string`
562
515
  */
563
- static inline mstr
564
- mstr_replace (const mstr_view string,
565
- const mstr_view find,
566
- const mstr_view subst)
567
- {
568
- if (find.len == 0) {
569
- // Finding an empty string would loop forever
570
- return mstr_copy (string);
571
- }
572
- // First copy the string
573
- mstr ret = mstr_copy (string);
574
- // Keep an index of how far we have processed
575
- size_t whence = 0;
576
- for (;;) {
577
- // Chop off the front that has already been processed
578
- mstr_view tail = mstrv_subview (ret.view, whence, SIZE_MAX);
579
- // Find where in that tail is the next needle
580
- int pos = mstr_find (tail, find);
581
- if (pos == -1) {
582
- // We're done
583
- break;
584
- }
585
- // Do the replacement
586
- assert (whence <= SIZE_MAX - (size_t) pos);
587
- mstr_assign (
588
- &ret, mstr_splice (ret.view, (size_t) pos + whence, find.len, subst));
589
- // Advance our position by how many chars we skipped and how many we
590
- // inserted
591
- whence += (size_t) pos + subst.len;
592
- }
593
- return ret;
516
+ static inline mstr mstr_replace(const mstr_view string, const mstr_view find, const mstr_view subst) {
517
+ if (find.len == 0) {
518
+ // Finding an empty string would loop forever
519
+ return mstr_copy(string);
520
+ }
521
+ // First copy the string
522
+ mstr ret = mstr_copy(string);
523
+ // Keep an index of how far we have processed
524
+ size_t whence = 0;
525
+ for (;;) {
526
+ // Chop off the front that has already been processed
527
+ mstr_view tail = mstrv_subview(ret.view, whence, SIZE_MAX);
528
+ // Find where in that tail is the next needle
529
+ int pos = mstr_find(tail, find);
530
+ if (pos == -1) {
531
+ // We're done
532
+ break;
533
+ }
534
+ // Do the replacement
535
+ assert(whence <= SIZE_MAX - (size_t)pos);
536
+ mstr_assign(&ret, mstr_splice(ret.view, (size_t)pos + whence, find.len, subst));
537
+ // Advance our position by how many chars we skipped and how many we
538
+ // inserted
539
+ whence += (size_t)pos + subst.len;
540
+ }
541
+ return ret;
594
542
  }
595
543
 
596
544
  /**
597
545
  * @brief Determine whether two strings are equivalent.
598
546
  */
599
- static inline bool
600
- mstr_eq (mstr_view left, mstr_view right)
601
- {
602
- if (left.len != right.len) {
603
- return false;
604
- }
605
- return memcmp (left.data, right.data, left.len) == 0;
547
+ static inline bool mstr_eq(mstr_view left, mstr_view right) {
548
+ if (left.len != right.len) {
549
+ return false;
550
+ }
551
+ return memcmp(left.data, right.data, left.len) == 0;
606
552
  }
607
553
 
608
554
  /**
609
555
  * @brief Determine whether two strings are equivalent ignoring case.
610
556
  */
611
- static inline bool
612
- mstr_eq_ignore_case (mstr_view left, mstr_view right)
613
- {
557
+ static inline bool mstr_eq_ignore_case(mstr_view left, mstr_view right) {
614
558
  #ifdef _WIN32
615
559
  #define _mstr_strncasecmp _strnicmp
616
560
  #else
617
561
  #define _mstr_strncasecmp strncasecmp
618
562
  #endif
619
563
 
620
- if (left.len != right.len) {
621
- return false;
622
- }
623
- return _mstr_strncasecmp (left.data, right.data, left.len) == 0;
564
+ if (left.len != right.len) {
565
+ return false;
566
+ }
567
+ return _mstr_strncasecmp(left.data, right.data, left.len) == 0;
624
568
  #undef _mstr_strncasecmp
625
569
  }
626
570
 
627
571
  /// Determine whether the given character is an printable ASCII codepoint
628
- static inline bool
629
- mstr_is_printable (char c)
630
- {
631
- return (c >= ' ' && c <= '~');
572
+ static inline bool mstr_is_printable(char c) {
573
+ return (c >= ' ' && c <= '~');
632
574
  }
633
575
 
634
576
  /// Write the given string to `out`, rendering non-printable characters as hex
635
577
  /// escapes
636
- static inline void
637
- _mstr_write_str_repr_ (FILE *out, mstr_view s)
638
- {
639
- for (char const *it = s.data; it != s.data + s.len; ++it) {
640
- if (mstr_is_printable (*it)) {
641
- fputc (*it, out);
642
- } else {
643
- fprintf (out, "\\x%.2x", (unsigned) (unsigned char) *it);
644
- }
645
- }
646
- }
647
-
648
- static inline void
649
- _mstr_assert_fail_ (mstr_view left,
650
- const char *predicate,
651
- mstr_view right,
652
- const char *file,
653
- int line)
654
- {
655
- fprintf (stderr, "%s:%d: ASSERTION FAILED: \"", file, line);
656
- _mstr_write_str_repr_ (stderr, left);
657
- fprintf (stderr, "\" %s \"", predicate);
658
- _mstr_write_str_repr_ (stderr, right);
659
- fprintf (stderr, "\"\n");
660
- abort ();
578
+ static inline void _mstr_write_str_repr_(FILE *out, mstr_view s) {
579
+ for (const char *it = s.data; it != s.data + s.len; ++it) {
580
+ if (mstr_is_printable(*it)) {
581
+ fputc(*it, out);
582
+ } else {
583
+ fprintf(out, "\\x%.2x", (unsigned)(unsigned char)*it);
584
+ }
585
+ }
661
586
  }
662
587
 
663
588
  static inline void
664
- _mstr_assert_ (mstr_view left,
665
- mstr_view right,
666
- bool (*pred) (mstr_view left, mstr_view right),
667
- bool B,
668
- const char *pred_str,
669
- const char *file,
670
- int line)
671
- {
672
- if (pred (left, right) != B) {
673
- mstr pstr = mstr_copy_cstr (pred_str);
674
- if (!B) {
675
- mstr_assign (&pstr, mstr_prepend (pstr.view, mstrv_lit ("not ")));
676
- }
677
- _mstr_assert_fail_ (left, pstr.data, right, file, line);
678
- }
679
- }
680
-
681
- #define MSTR_ASSERT(Bool, Left, Pred, Right) \
682
- (_mstr_assert_ ( \
683
- (Left), (Right), mstr_##Pred, (Bool), #Pred, __FILE__, __LINE__))
589
+ _mstr_assert_fail_(mstr_view left, const char *predicate, mstr_view right, const char *file, int line) {
590
+ fprintf(stderr, "%s:%d: ASSERTION FAILED: \"", file, line);
591
+ _mstr_write_str_repr_(stderr, left);
592
+ fprintf(stderr, "\" %s \"", predicate);
593
+ _mstr_write_str_repr_(stderr, right);
594
+ fprintf(stderr, "\"\n");
595
+ abort();
596
+ }
597
+
598
+ static inline void _mstr_assert_(mstr_view left,
599
+ mstr_view right,
600
+ bool (*pred)(mstr_view left, mstr_view right),
601
+ bool B,
602
+ const char *pred_str,
603
+ const char *file,
604
+ int line) {
605
+ if (pred(left, right) != B) {
606
+ mstr pstr = mstr_copy_cstr(pred_str);
607
+ if (!B) {
608
+ mstr_assign(&pstr, mstr_prepend(pstr.view, mstrv_lit("not ")));
609
+ }
610
+ _mstr_assert_fail_(left, pstr.data, right, file, line);
611
+ }
612
+ }
613
+
614
+ #define MSTR_ASSERT(Bool, Left, Pred, Right) \
615
+ (_mstr_assert_((Left), (Right), mstr_##Pred, (Bool), #Pred, __FILE__, __LINE__))
684
616
 
685
617
  /**
686
618
  * @brief Assert that two strings are equivalent.
687
619
  *
688
620
  * Prints and error message and aborts if they are not
689
621
  */
690
- #define MSTR_ASSERT_EQ(Left, Right) MSTR_ASSERT (true, Left, eq, Right)
622
+ #define MSTR_ASSERT_EQ(Left, Right) MSTR_ASSERT(true, Left, eq, Right)
691
623
 
692
624
  /**
693
625
  * @brief Determine whether the given string contains the given substring
@@ -697,113 +629,88 @@ _mstr_assert_ (mstr_view left,
697
629
  * @return true If `given` contains at least one occurrence of `needle`
698
630
  * @return false Otherwise
699
631
  */
700
- static inline bool
701
- mstr_contains (mstr_view given, mstr_view needle)
702
- {
703
- return mstr_find (given, needle) >= 0;
632
+ static inline bool mstr_contains(mstr_view given, mstr_view needle) {
633
+ return mstr_find(given, needle) >= 0;
704
634
  }
705
635
 
706
636
  /**
707
637
  * @brief Determine whether `given` starts with `prefix`
708
638
  */
709
- static inline bool
710
- mstr_starts_with (mstr_view given, mstr_view prefix)
711
- {
712
- given = mstrv_subview (given, 0, prefix.len);
713
- return mstr_eq (given, prefix);
639
+ static inline bool mstr_starts_with(mstr_view given, mstr_view prefix) {
640
+ given = mstrv_subview(given, 0, prefix.len);
641
+ return mstr_eq(given, prefix);
714
642
  }
715
643
 
716
644
  /**
717
645
  * @brief Determine whether `given` ends with `suffix`
718
646
  */
719
- static inline bool
720
- mstr_ends_with (mstr_view given, mstr_view suffix)
721
- {
722
- if (suffix.len > given.len) {
723
- return false;
724
- }
725
- given = mstrv_subview (given, given.len - suffix.len, SIZE_MAX);
726
- return mstr_eq (given, suffix);
647
+ static inline bool mstr_ends_with(mstr_view given, mstr_view suffix) {
648
+ if (suffix.len > given.len) {
649
+ return false;
650
+ }
651
+ given = mstrv_subview(given, given.len - suffix.len, SIZE_MAX);
652
+ return mstr_eq(given, suffix);
727
653
  }
728
654
 
729
655
  /// Compound in-place version of @ref mstr_splice
730
- static inline void
731
- mstr_inplace_splice (mstr *s, size_t at, size_t del_count, mstr_view insert)
732
- {
733
- mstr_assign (s, mstr_splice (s->view, at, del_count, insert));
656
+ static inline void mstr_inplace_splice(mstr *s, size_t at, size_t del_count, mstr_view insert) {
657
+ mstr_assign(s, mstr_splice(s->view, at, del_count, insert));
734
658
  }
735
659
 
736
660
  /// Compound in-place version of @ref mstr_append
737
- static inline void
738
- mstr_inplace_append (mstr *s, mstr_view suffix)
739
- {
740
- mstr_assign (s, mstr_append (s->view, suffix));
661
+ static inline void mstr_inplace_append(mstr *s, mstr_view suffix) {
662
+ mstr_assign(s, mstr_append(s->view, suffix));
741
663
  }
742
664
 
743
665
  /// Compound in-place version of @ref mstr_prepend
744
- static inline void
745
- mstr_inplace_prepend (mstr *s, mstr_view prefix)
746
- {
747
- mstr_assign (s, mstr_prepend (s->view, prefix));
666
+ static inline void mstr_inplace_prepend(mstr *s, mstr_view prefix) {
667
+ mstr_assign(s, mstr_prepend(s->view, prefix));
748
668
  }
749
669
 
750
670
  /// Compound in-place version of @ref mstr_insert
751
- static inline void
752
- mstr_inplace_insert (mstr *s, size_t at, mstr_view infix)
753
- {
754
- mstr_assign (s, mstr_insert (s->view, at, infix));
671
+ static inline void mstr_inplace_insert(mstr *s, size_t at, mstr_view infix) {
672
+ mstr_assign(s, mstr_insert(s->view, at, infix));
755
673
  }
756
674
 
757
675
  /// Compound in-place version of @ref mstr_erase
758
- static inline void
759
- mstr_inplace_erase (mstr *s, size_t at, size_t count)
760
- {
761
- mstr_assign (s, mstr_erase (s->view, at, count));
676
+ static inline void mstr_inplace_erase(mstr *s, size_t at, size_t count) {
677
+ mstr_assign(s, mstr_erase(s->view, at, count));
762
678
  }
763
679
 
764
680
  /// Compound in-place version of @ref mstr_remove_prefix
765
- static inline void
766
- mstr_inplace_remove_prefix (mstr *s, size_t len)
767
- {
768
- mstr_assign (s, mstr_remove_prefix (s->view, len));
681
+ static inline void mstr_inplace_remove_prefix(mstr *s, size_t len) {
682
+ mstr_assign(s, mstr_remove_prefix(s->view, len));
769
683
  }
770
684
 
771
685
  /// Compound in-place version of @ref mstr_remove_suffix
772
- static inline void
773
- mstr_inplace_remove_suffix (mstr *s, size_t len)
774
- {
775
- mstr_assign (s, mstr_remove_suffix (s->view, len));
686
+ static inline void mstr_inplace_remove_suffix(mstr *s, size_t len) {
687
+ mstr_assign(s, mstr_remove_suffix(s->view, len));
776
688
  }
777
689
 
778
690
  /// Compound in-place version of @ref mstr_substr
779
- static inline void
780
- mstr_inplace_substr (mstr *s, size_t at, size_t count)
781
- {
782
- mstr_assign (s, mstr_substr (s->view, at, count));
691
+ static inline void mstr_inplace_substr(mstr *s, size_t at, size_t count) {
692
+ mstr_assign(s, mstr_substr(s->view, at, count));
783
693
  }
784
694
 
785
695
  /// Compound in-place version of @ref mstr_trunc
786
- static inline void
787
- mstr_inplace_trunc (mstr *s, size_t new_len)
788
- {
789
- mstr_assign (s, mstr_trunc (s->view, new_len));
696
+ static inline void mstr_inplace_trunc(mstr *s, size_t new_len) {
697
+ mstr_assign(s, mstr_trunc(s->view, new_len));
790
698
  }
791
699
 
792
700
  /// Compound in-place version of @ref mstr_replace
793
- static inline void
794
- mstr_inplace_replace (mstr *s, mstr_view find, mstr_view subst)
795
- {
796
- mstr_assign (s, mstr_replace (s->view, find, subst));
701
+ static inline void mstr_inplace_replace(mstr *s, mstr_view find, mstr_view subst) {
702
+ mstr_assign(s, mstr_replace(s->view, find, subst));
797
703
  }
798
704
 
799
705
  #ifdef _WIN32
800
706
  #include "./windows-lean.h"
707
+
801
708
  /**
802
709
  * @brief The result type of mstr_win32_widen
803
710
  */
804
711
  typedef struct mstr_widen_result {
805
- wchar_t *wstring;
806
- int error;
712
+ wchar_t *wstring;
713
+ int error;
807
714
  } mstr_widen_result;
808
715
 
809
716
  /**
@@ -814,29 +721,25 @@ typedef struct mstr_widen_result {
814
721
  *
815
722
  * @note The returned @ref mstr_widen_result::wstring must be given to free()
816
723
  */
817
- static inline mstr_widen_result
818
- mstr_win32_widen (mstr_view str)
819
- {
820
- assert (str.len <= INT_MAX);
821
- int length = MultiByteToWideChar (
822
- CP_UTF8, MB_ERR_INVALID_CHARS, str.data, (int) str.len, NULL, 0);
823
- if (length == 0 && str.len != 0) {
824
- return MLIB_INIT (mstr_widen_result){NULL, (int) GetLastError ()};
825
- }
826
- wchar_t *ret = (wchar_t *) calloc (length + 1, sizeof (wchar_t));
827
- assert (length < INT_MAX);
828
- int got_length = MultiByteToWideChar (
829
- CP_UTF8, MB_ERR_INVALID_CHARS, str.data, (int) str.len, ret, length + 1);
830
- assert (got_length == length);
831
- return MLIB_INIT (mstr_widen_result){ret, 0};
724
+ static inline mstr_widen_result mstr_win32_widen(mstr_view str) {
725
+ assert(str.len <= INT_MAX);
726
+ int length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data, (int)str.len, NULL, 0);
727
+ if (length == 0 && str.len != 0) {
728
+ return MLIB_INIT(mstr_widen_result){NULL, (int)GetLastError()};
729
+ }
730
+ wchar_t *ret = (wchar_t *)calloc(length + 1, sizeof(wchar_t));
731
+ assert(length < INT_MAX);
732
+ int got_length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data, (int)str.len, ret, length + 1);
733
+ assert(got_length == length);
734
+ return MLIB_INIT(mstr_widen_result){ret, 0};
832
735
  }
833
736
 
834
737
  /**
835
738
  * @brief The result type of mstr_win32_narrow
836
739
  */
837
740
  typedef struct mstr_narrow_result {
838
- mstr string;
839
- int error;
741
+ mstr string;
742
+ int error;
840
743
  } mstr_narrow_result;
841
744
 
842
745
  /**
@@ -849,102 +752,87 @@ typedef struct mstr_narrow_result {
849
752
  * @note The returned @ref mstr_narrow_result::string must be freed with
850
753
  * mstr_free()
851
754
  */
852
- static inline mstr_narrow_result
853
- mstr_win32_narrow (const wchar_t *wstring)
854
- {
855
- // Some older versions of MinGW fail to include the WC_ERR_INVALID_CHARS
856
- // flag, so we will specify it manually:
857
- DWORD wcflags = 0x80; // WC_ERR_INVALID_CHARS
858
- int length = WideCharToMultiByte (CP_UTF8,
859
- wcflags,
860
- wstring,
861
- -1 /* wstring is null-terminated */,
862
- NULL,
863
- 0,
864
- NULL,
865
- NULL);
866
- if (length == 0 && wstring[0] != 0) {
867
- return MLIB_INIT (mstr_narrow_result){MSTR_NULL, (int) GetLastError ()};
868
- }
869
- // Allocate a new string, not including the null terminator
870
- mstr_mut ret = mstr_new ((size_t) (length - 1));
871
- int got_len = WideCharToMultiByte (CP_UTF8,
755
+ static inline mstr_narrow_result mstr_win32_narrow(const wchar_t *wstring) {
756
+ // Some older versions of MinGW fail to include the WC_ERR_INVALID_CHARS
757
+ // flag, so we will specify it manually:
758
+ DWORD wcflags = 0x80; // WC_ERR_INVALID_CHARS
759
+ int length =
760
+ WideCharToMultiByte(CP_UTF8, wcflags, wstring, -1 /* wstring is null-terminated */, NULL, 0, NULL, NULL);
761
+ if (length == 0 && wstring[0] != 0) {
762
+ return MLIB_INIT(mstr_narrow_result){MSTR_NULL, (int)GetLastError()};
763
+ }
764
+ // Allocate a new string, not including the null terminator
765
+ mstr_mut ret = mstr_new((size_t)(length - 1));
766
+ int got_len = WideCharToMultiByte(CP_UTF8,
872
767
  wcflags,
873
768
  wstring,
874
769
  -1,
875
770
  ret.data,
876
771
  // Plus one byte for the NUL
877
- (int) (ret.len + 1),
772
+ (int)(ret.len + 1),
878
773
  NULL,
879
774
  NULL);
880
- assert (length == got_len);
881
- return MLIB_INIT (mstr_narrow_result){ret.mstr, 0};
775
+ assert(length == got_len);
776
+ return MLIB_INIT(mstr_narrow_result){ret.mstr, 0};
882
777
  }
883
778
  #endif
884
779
 
885
780
  /// Iteration state for string splitting
886
781
  struct _mstr_split_iter_ {
887
- /// What hasn't been parsed yet
888
- mstr_view remaining;
889
- /// The string that we split on
890
- mstr_view splitter;
891
- /// The current part
892
- mstr_view part;
893
- /// A once-var for the inner loop. Set to 1 by iter_next, then decremented
894
- int once;
895
- /// The loop state. Starts at zero. Set to one when we part the final split.
896
- /// Set to two to break out of the loop.
897
- int state;
782
+ /// What hasn't been parsed yet
783
+ mstr_view remaining;
784
+ /// The string that we split on
785
+ mstr_view splitter;
786
+ /// The current part
787
+ mstr_view part;
788
+ /// A once-var for the inner loop. Set to 1 by iter_next, then decremented
789
+ int once;
790
+ /// The loop state. Starts at zero. Set to one when we part the final split.
791
+ /// Set to two to break out of the loop.
792
+ int state;
898
793
  };
899
794
 
900
795
  /// Hidden function to advance a string-split iterator
901
- static inline void
902
- _mstr_split_iter_next_ (struct _mstr_split_iter_ *iter)
903
- {
904
- if (iter->once == 1) {
905
- // We only get here if the loop body hit a 'break', skipping the decrement
906
- // of the 'once'. Break out of the whole loop, as the user expects.
907
- iter->state = 2;
908
- return;
909
- }
910
- if (iter->state == 1) {
911
- // We just completed the final loop pass.
912
- iter->state = 2;
913
- return;
914
- }
915
- // Find the next occurence of the token
916
- const int pos = mstr_find (iter->remaining, iter->splitter);
917
- if (pos < 0) {
918
- // There are no more occurences. yield the remaining string
919
- iter->part = iter->remaining;
920
- iter->remaining = mstrv_subview (iter->remaining, iter->remaining.len, 0);
921
- // Set state to 1 to break on the next pass
922
- iter->state = 1;
923
- } else {
924
- // Advance our parts:
925
- iter->part = mstrv_subview (iter->remaining, 0, (size_t) pos);
926
- assert (iter->splitter.len <= SIZE_MAX - (size_t) pos);
927
- iter->remaining = mstrv_subview (
928
- iter->remaining, (size_t) pos + iter->splitter.len, SIZE_MAX);
929
- }
930
- // Prime the inner "loop" to execute once
931
- iter->once = 1;
796
+ static inline void _mstr_split_iter_next_(struct _mstr_split_iter_ *iter) {
797
+ if (iter->once == 1) {
798
+ // We only get here if the loop body hit a 'break', skipping the decrement
799
+ // of the 'once'. Break out of the whole loop, as the user expects.
800
+ iter->state = 2;
801
+ return;
802
+ }
803
+ if (iter->state == 1) {
804
+ // We just completed the final loop pass.
805
+ iter->state = 2;
806
+ return;
807
+ }
808
+ // Find the next occurence of the token
809
+ const int pos = mstr_find(iter->remaining, iter->splitter);
810
+ if (pos < 0) {
811
+ // There are no more occurences. yield the remaining string
812
+ iter->part = iter->remaining;
813
+ iter->remaining = mstrv_subview(iter->remaining, iter->remaining.len, 0);
814
+ // Set state to 1 to break on the next pass
815
+ iter->state = 1;
816
+ } else {
817
+ // Advance our parts:
818
+ iter->part = mstrv_subview(iter->remaining, 0, (size_t)pos);
819
+ assert(iter->splitter.len <= SIZE_MAX - (size_t)pos);
820
+ iter->remaining = mstrv_subview(iter->remaining, (size_t)pos + iter->splitter.len, SIZE_MAX);
821
+ }
822
+ // Prime the inner "loop" to execute once
823
+ iter->once = 1;
932
824
  }
933
825
 
934
826
  /// init a new split iterator
935
- static inline struct _mstr_split_iter_
936
- _mstr_split_iter_begin_ (mstr_view str, mstr_view split)
937
- {
938
- struct _mstr_split_iter_ iter = {str, split};
939
- _mstr_split_iter_next_ (&iter);
940
- return iter;
827
+ static inline struct _mstr_split_iter_ _mstr_split_iter_begin_(mstr_view str, mstr_view split) {
828
+ struct _mstr_split_iter_ iter = {str, split};
829
+ _mstr_split_iter_next_(&iter);
830
+ return iter;
941
831
  }
942
832
 
943
833
  /// Check whether we are done iterating
944
- static inline bool
945
- _mstr_split_iter_done_ (struct _mstr_split_iter_ *iter)
946
- {
947
- return iter->state == 2;
834
+ static inline bool _mstr_split_iter_done_(struct _mstr_split_iter_ *iter) {
835
+ return iter->state == 2;
948
836
  }
949
837
 
950
838
  // clang-format off
@@ -961,18 +849,16 @@ _mstr_split_iter_done_ (struct _mstr_split_iter_ *iter)
961
849
  for (mstr_view const LineVar = _iter_var_.part; \
962
850
  _iter_var_.once; \
963
851
  --_iter_var_.once)
852
+
964
853
  // clang-format on
965
854
 
966
855
  /**
967
856
  * @brief Equivalent to strlen(), but has a constexpr annotation.
968
857
  */
969
- static mlib_constexpr_fn size_t
970
- mlib_strlen (const char *s)
971
- {
972
- size_t r = 0;
973
- for (; *s; ++r, ++s) {
974
- }
975
- return r;
858
+ static mlib_constexpr_fn size_t mlib_strlen(const char *s) {
859
+ size_t r = 0;
860
+ for (; *s; ++r, ++s) {}
861
+ return r;
976
862
  }
977
863
 
978
864
  /**
@@ -991,36 +877,31 @@ mlib_strlen (const char *s)
991
877
  * @note Characters beyond (dst + R) are unmodified. dst[R] is guaranteed to
992
878
  * be a null terminator.
993
879
  */
994
- static mlib_constexpr_fn size_t
995
- mlib_strnmcopy (char *dst,
996
- size_t dst_bufsize,
997
- const char *src,
998
- size_t src_bufsize)
999
- {
1000
- // No empty destination, since we *must* write a null terminator:
1001
- assert (dst_bufsize > 0);
1002
- // The maximum number of characters in the dest is one less than the buffer
1003
- // size, since we need room for the null terminator:
1004
- const size_t dstlen = dst_bufsize - 1u;
1005
- // The actual maximum number of characters we can copy is the less of the
1006
- // source length and the dest length:
1007
- const size_t minlen = dstlen < src_bufsize ? dstlen : src_bufsize;
1008
- // Track what we copy:
1009
- size_t ncopied = 0;
1010
- while (ncopied != minlen // Stop if we hit our character limit
1011
- && *src != 0 // Or if we hit the null terminator in the source
1012
- ) {
1013
- // Copy:
1014
- *dst = *src;
1015
- // Advance:
1016
- ++dst;
1017
- ++src;
1018
- ++ncopied;
1019
- }
1020
- // "dst" now points past the final character we copied (if any), and is still
1021
- // in-bounds. This will be the null terminator.
1022
- *dst = 0;
1023
- return ncopied;
880
+ static mlib_constexpr_fn size_t mlib_strnmcopy(char *dst, size_t dst_bufsize, const char *src, size_t src_bufsize) {
881
+ // No empty destination, since we *must* write a null terminator:
882
+ assert(dst_bufsize > 0);
883
+ // The maximum number of characters in the dest is one less than the buffer
884
+ // size, since we need room for the null terminator:
885
+ const size_t dstlen = dst_bufsize - 1u;
886
+ // The actual maximum number of characters we can copy is the less of the
887
+ // source length and the dest length:
888
+ const size_t minlen = dstlen < src_bufsize ? dstlen : src_bufsize;
889
+ // Track what we copy:
890
+ size_t ncopied = 0;
891
+ while (ncopied != minlen // Stop if we hit our character limit
892
+ && *src != 0 // Or if we hit the null terminator in the source
893
+ ) {
894
+ // Copy:
895
+ *dst = *src;
896
+ // Advance:
897
+ ++dst;
898
+ ++src;
899
+ ++ncopied;
900
+ }
901
+ // "dst" now points past the final character we copied (if any), and is still
902
+ // in-bounds. This will be the null terminator.
903
+ *dst = 0;
904
+ return ncopied;
1024
905
  }
1025
906
 
1026
907
  MLIB_C_LINKAGE_END