slidge-whatsapp 0.2.5__cp311-cp311-manylinux_2_36_aarch64.whl → 0.2.7__cp311-cp311-manylinux_2_36_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of slidge-whatsapp might be problematic. Click here for more details.

Files changed (357) hide show
  1. slidge_whatsapp/config.py +3 -0
  2. slidge_whatsapp/event.go +31 -26
  3. slidge_whatsapp/gateway.go +13 -9
  4. slidge_whatsapp/gateway.py +2 -2
  5. slidge_whatsapp/generated/_whatsapp.cpython-311-aarch64-linux-gnu.h +170 -170
  6. slidge_whatsapp/generated/_whatsapp.cpython-311-aarch64-linux-gnu.so +0 -0
  7. slidge_whatsapp/generated/build.py +135 -135
  8. slidge_whatsapp/generated/whatsapp.c +1496 -1496
  9. slidge_whatsapp/generated/whatsapp.go +1137 -1137
  10. slidge_whatsapp/generated/whatsapp.py +1216 -1216
  11. slidge_whatsapp/generated/whatsapp_go.h +170 -170
  12. slidge_whatsapp/go.mod +15 -12
  13. slidge_whatsapp/go.sum +35 -29
  14. slidge_whatsapp/media/media.go +21 -11
  15. slidge_whatsapp/session.go +73 -66
  16. slidge_whatsapp/vendor/github.com/ebitengine/purego/dlfcn.go +4 -4
  17. slidge_whatsapp/vendor/github.com/ebitengine/purego/dlfcn_darwin.go +0 -5
  18. slidge_whatsapp/vendor/github.com/ebitengine/purego/internal/fakecgo/go_libinit.go +3 -0
  19. slidge_whatsapp/vendor/github.com/ebitengine/purego/internal/fakecgo/symbols.go +40 -20
  20. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/CHANGELOG.md +14 -1
  21. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/ffi.go +2 -2
  22. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/fun.go +10 -2
  23. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/lib.go +1 -1
  24. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/lib_unix.go +1 -1
  25. slidge_whatsapp/vendor/github.com/jupiterrider/ffi/lib_windows.go +1 -1
  26. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/README.md +2 -7
  27. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/callback.go +2 -1
  28. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c +8510 -5090
  29. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.h +344 -150
  30. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3.go +57 -23
  31. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.c +4 -0
  32. slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.go +4 -0
  33. slidge_whatsapp/vendor/github.com/petermattis/goid/.gitignore +4 -0
  34. slidge_whatsapp/vendor/github.com/petermattis/goid/LICENSE +202 -0
  35. slidge_whatsapp/vendor/github.com/petermattis/goid/README.md +4 -0
  36. slidge_whatsapp/vendor/github.com/petermattis/goid/goid.go +35 -0
  37. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_gccgo.go +26 -0
  38. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_go1.3.c +23 -0
  39. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_go1.3.go +22 -0
  40. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_go1.4.go +35 -0
  41. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_go1.4.s +18 -0
  42. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_go1.5.go +28 -0
  43. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_go1.5.s +44 -0
  44. slidge_whatsapp/vendor/github.com/petermattis/goid/goid_slow.go +24 -0
  45. slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_gccgo_go1.8.go +17 -0
  46. slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.23.go +38 -0
  47. slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.5.go +57 -0
  48. slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.6.go +43 -0
  49. slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.9.go +37 -0
  50. slidge_whatsapp/vendor/github.com/rs/zerolog/CONTRIBUTING.md +43 -0
  51. slidge_whatsapp/vendor/github.com/rs/zerolog/README.md +31 -0
  52. slidge_whatsapp/vendor/github.com/rs/zerolog/console.go +20 -5
  53. slidge_whatsapp/vendor/github.com/rs/zerolog/log/log.go +131 -0
  54. slidge_whatsapp/vendor/github.com/rs/zerolog/log.go +1 -1
  55. slidge_whatsapp/vendor/github.com/rs/zerolog/sampler.go +4 -1
  56. slidge_whatsapp/vendor/github.com/rs/zerolog/writer.go +9 -0
  57. slidge_whatsapp/vendor/go.mau.fi/libsignal/groups/GroupCipher.go +17 -6
  58. slidge_whatsapp/vendor/go.mau.fi/libsignal/groups/GroupSessionBuilder.go +17 -7
  59. slidge_whatsapp/vendor/go.mau.fi/libsignal/groups/state/store/SenderKeyStore.go +4 -2
  60. slidge_whatsapp/vendor/go.mau.fi/libsignal/keys/chain/ChainKey.go +1 -0
  61. slidge_whatsapp/vendor/go.mau.fi/libsignal/keys/identity/IdentityKey.go +1 -0
  62. slidge_whatsapp/vendor/go.mau.fi/libsignal/logger/DefaultLogger.go +2 -2
  63. slidge_whatsapp/vendor/go.mau.fi/libsignal/serialize/FingerprintProtocol.pb.go +3 -2
  64. slidge_whatsapp/vendor/go.mau.fi/libsignal/serialize/LocalStorageProtocol.pb.go +3 -2
  65. slidge_whatsapp/vendor/go.mau.fi/libsignal/serialize/WhisperTextProtocol.pb.go +3 -2
  66. slidge_whatsapp/vendor/go.mau.fi/libsignal/session/Session.go +41 -17
  67. slidge_whatsapp/vendor/go.mau.fi/libsignal/session/SessionCipher.go +64 -30
  68. slidge_whatsapp/vendor/go.mau.fi/libsignal/state/store/IdentityKeyStore.go +5 -3
  69. slidge_whatsapp/vendor/go.mau.fi/libsignal/state/store/MessageKeyStore.go +6 -4
  70. slidge_whatsapp/vendor/go.mau.fi/libsignal/state/store/PreKeyStore.go +6 -4
  71. slidge_whatsapp/vendor/go.mau.fi/libsignal/state/store/SessionStore.go +8 -6
  72. slidge_whatsapp/vendor/go.mau.fi/libsignal/state/store/SignedPreKeyStore.go +7 -5
  73. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/connlog.go +257 -0
  74. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/database.go +309 -0
  75. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/iter.go +233 -0
  76. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/json.go +47 -0
  77. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/log.go +129 -0
  78. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/massinsert.go +164 -0
  79. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/queryhelper.go +137 -0
  80. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/reflectscan.go +30 -0
  81. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/transaction.go +180 -0
  82. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/upgrades.go +250 -0
  83. slidge_whatsapp/vendor/go.mau.fi/util/dbutil/upgradetable.go +331 -0
  84. slidge_whatsapp/vendor/go.mau.fi/util/exerrors/dualerror.go +33 -0
  85. slidge_whatsapp/vendor/go.mau.fi/util/exerrors/must.go +23 -0
  86. slidge_whatsapp/vendor/go.mau.fi/util/exhttp/cors.go +32 -0
  87. slidge_whatsapp/vendor/go.mau.fi/util/exhttp/handleerrors.go +64 -0
  88. slidge_whatsapp/vendor/go.mau.fi/util/exhttp/json.go +36 -0
  89. slidge_whatsapp/vendor/go.mau.fi/util/exhttp/middleware.go +30 -0
  90. slidge_whatsapp/vendor/go.mau.fi/util/exhttp/networkerror.go +37 -0
  91. slidge_whatsapp/vendor/go.mau.fi/util/exstrings/stringutil.go +76 -0
  92. slidge_whatsapp/vendor/go.mau.fi/util/exsync/event.go +88 -0
  93. slidge_whatsapp/vendor/go.mau.fi/util/exsync/returnonce.go +25 -0
  94. slidge_whatsapp/vendor/go.mau.fi/util/exsync/ringbuffer.go +139 -0
  95. slidge_whatsapp/vendor/go.mau.fi/util/exsync/syncmap.go +94 -0
  96. slidge_whatsapp/vendor/go.mau.fi/util/exsync/syncset.go +136 -0
  97. slidge_whatsapp/vendor/go.mau.fi/util/exzerolog/callermarshal.go +28 -0
  98. slidge_whatsapp/vendor/go.mau.fi/util/exzerolog/defaults.go +32 -0
  99. slidge_whatsapp/vendor/go.mau.fi/util/exzerolog/generics.go +45 -0
  100. slidge_whatsapp/vendor/go.mau.fi/util/exzerolog/writer.go +81 -0
  101. slidge_whatsapp/vendor/go.mau.fi/util/ptr/ptr.go +43 -0
  102. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/decode.go +27 -26
  103. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/encode.go +4 -3
  104. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/keys.go +5 -4
  105. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate.go +27 -25
  106. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/armadillomessage.go +40 -7
  107. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/binary/encoder.go +1 -1
  108. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/broadcast.go +5 -4
  109. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/call.go +1 -1
  110. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/client.go +119 -37
  111. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/connectionevents.go +29 -11
  112. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/download-to-file.go +63 -30
  113. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/download.go +74 -34
  114. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/errors.go +1 -0
  115. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/group.go +61 -31
  116. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/internals.go +188 -152
  117. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/keepalive.go +3 -2
  118. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaconn.go +5 -3
  119. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaretry.go +2 -1
  120. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/message.go +444 -135
  121. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/msgsecret.go +118 -31
  122. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/notification.go +78 -42
  123. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair-code.go +7 -4
  124. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair.go +42 -18
  125. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/prekeys.go +9 -5
  126. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/presence.go +2 -1
  127. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/privacysettings.go +10 -11
  128. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/extra.go +7 -0
  129. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloAddMessage/InstamadilloAddMessage.pb.go +983 -0
  130. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloAddMessage/InstamadilloAddMessage.proto +85 -0
  131. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloAddMessage/extra.go +3 -0
  132. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeActionLog/InstamadilloCoreTypeActionLog.pb.go +197 -0
  133. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeActionLog/InstamadilloCoreTypeActionLog.proto +13 -0
  134. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeAdminMessage/InstamadilloCoreTypeAdminMessage.pb.go +279 -0
  135. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeAdminMessage/InstamadilloCoreTypeAdminMessage.proto +21 -0
  136. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeCollection/InstamadilloCoreTypeCollection.pb.go +137 -0
  137. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeCollection/InstamadilloCoreTypeCollection.proto +10 -0
  138. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeLink/InstamadilloCoreTypeLink.pb.go +313 -0
  139. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeLink/InstamadilloCoreTypeLink.proto +27 -0
  140. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeMedia/InstamadilloCoreTypeMedia.pb.go +1299 -0
  141. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeMedia/InstamadilloCoreTypeMedia.proto +112 -0
  142. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeText/InstamadilloCoreTypeText.pb.go +514 -0
  143. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeText/InstamadilloCoreTypeText.proto +47 -0
  144. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloDeleteMessage/InstamadilloDeleteMessage.pb.go +123 -0
  145. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloDeleteMessage/InstamadilloDeleteMessage.proto +7 -0
  146. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloDeleteMessage/extra.go +3 -0
  147. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloSupplementMessage/InstamadilloSupplementMessage.pb.go +720 -0
  148. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloSupplementMessage/InstamadilloSupplementMessage.proto +59 -0
  149. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloSupplementMessage/extra.go +3 -0
  150. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloTransportPayload/InstamadilloTransportPayload.pb.go +365 -0
  151. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloTransportPayload/InstamadilloTransportPayload.proto +33 -0
  152. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloXmaContentRef/InstamadilloXmaContentRef.pb.go +1238 -0
  153. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloXmaContentRef/InstamadilloXmaContentRef.proto +105 -0
  154. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAdv/WAAdv.pb.go +39 -9
  155. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloApplication/WAArmadilloApplication.pb.go +354 -175
  156. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloApplication/WAArmadilloApplication.proto +5 -5
  157. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloXMA/WAArmadilloXMA.pb.go +170 -15
  158. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloXMA/WAArmadilloXMA.proto +4 -0
  159. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCert/WACert.pb.go +29 -9
  160. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waChatLockSettings/WAProtobufsChatLockSettings.pb.go +13 -9
  161. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCommon/WACommon.pb.go +344 -31
  162. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCommon/WACommon.proto +26 -0
  163. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/{WAWebProtobufsCompanionReg.pb.go → WACompanionReg.pb.go} +184 -89
  164. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/{WAWebProtobufsCompanionReg.proto → WACompanionReg.proto} +2 -1
  165. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waConsumerApplication/WAConsumerApplication.pb.go +173 -9
  166. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.pb.go +78 -16
  167. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.proto +5 -0
  168. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.pb.go +7428 -2151
  169. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.proto +373 -44
  170. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.pb.go +456 -135
  171. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.proto +14 -0
  172. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waLidMigrationSyncPayload/WAWebProtobufLidMigrationSyncPayload.pb.go +198 -0
  173. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waLidMigrationSyncPayload/WAWebProtobufLidMigrationSyncPayload.proto +14 -0
  174. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMediaTransport/WAMediaTransport.pb.go +162 -9
  175. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMediaTransport/WAMediaTransport.proto +1 -0
  176. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMmsRetry/WAMmsRetry.pb.go +32 -9
  177. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMmsRetry/WAMmsRetry.proto +1 -0
  178. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgApplication/WAMsgApplication.pb.go +192 -52
  179. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgApplication/WAMsgApplication.proto +8 -0
  180. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgTransport/WAMsgTransport.pb.go +60 -9
  181. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgTransport/extra.go +7 -6
  182. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMultiDevice/WAMultiDevice.pb.go +39 -9
  183. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waServerSync/WAServerSync.pb.go +61 -9
  184. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.pb.go +800 -0
  185. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.proto +72 -0
  186. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.pb.go +1344 -438
  187. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.proto +52 -0
  188. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waUserPassword/WAProtobufsUserPassword.pb.go +27 -9
  189. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waVnameCert/WAWebProtobufsVnameCert.pb.go +59 -9
  190. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.pb.go +382 -78
  191. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.proto +8 -0
  192. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.pb.go +563 -9
  193. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.proto +4 -0
  194. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/receipt.go +25 -9
  195. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/reportingfields.json +1 -0
  196. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/reportingtoken.go +176 -0
  197. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/retry.go +39 -21
  198. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/send.go +261 -75
  199. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/sendfb.go +28 -16
  200. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +3 -1
  201. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/noop.go +85 -43
  202. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/signal.go +75 -88
  203. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go +86 -65
  204. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/lidmap.go +186 -0
  205. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go +291 -167
  206. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/00-latest-schema.sql +155 -0
  207. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/03-message-secrets.sql +11 -0
  208. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/04-privacy-tokens.sql +8 -0
  209. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/05-account-jid-format.sql +2 -0
  210. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/06-facebook-uuid.sql +2 -0
  211. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/07-account-lid.sql +2 -0
  212. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/08-lid-mapping.sql +5 -0
  213. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/09-decryption-buffer.sql +10 -0
  214. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/10-chat-db-lid-migration-ts.sql +2 -0
  215. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrades/upgrades.go +22 -0
  216. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/store.go +107 -56
  217. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/botmap.go +210 -0
  218. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/events/events.go +13 -2
  219. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/group.go +15 -6
  220. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/jid.go +7 -8
  221. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/message.go +18 -0
  222. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/update.go +3 -2
  223. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/upload.go +1 -1
  224. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/user.go +47 -29
  225. slidge_whatsapp/vendor/golang.org/x/exp/LICENSE +27 -0
  226. slidge_whatsapp/vendor/golang.org/x/exp/PATENTS +22 -0
  227. slidge_whatsapp/vendor/golang.org/x/exp/constraints/constraints.go +54 -0
  228. slidge_whatsapp/vendor/golang.org/x/net/http/httpguts/guts.go +50 -0
  229. slidge_whatsapp/vendor/golang.org/x/net/http/httpguts/httplex.go +347 -0
  230. slidge_whatsapp/vendor/golang.org/x/net/http2/.gitignore +2 -0
  231. slidge_whatsapp/vendor/golang.org/x/net/http2/ascii.go +53 -0
  232. slidge_whatsapp/vendor/golang.org/x/net/http2/ciphers.go +641 -0
  233. slidge_whatsapp/vendor/golang.org/x/net/http2/client_conn_pool.go +311 -0
  234. slidge_whatsapp/vendor/golang.org/x/net/http2/config.go +122 -0
  235. slidge_whatsapp/vendor/golang.org/x/net/http2/config_go124.go +61 -0
  236. slidge_whatsapp/vendor/golang.org/x/net/http2/config_pre_go124.go +16 -0
  237. slidge_whatsapp/vendor/golang.org/x/net/http2/databuffer.go +149 -0
  238. slidge_whatsapp/vendor/golang.org/x/net/http2/errors.go +145 -0
  239. slidge_whatsapp/vendor/golang.org/x/net/http2/flow.go +120 -0
  240. slidge_whatsapp/vendor/golang.org/x/net/http2/frame.go +1702 -0
  241. slidge_whatsapp/vendor/golang.org/x/net/http2/gotrack.go +170 -0
  242. slidge_whatsapp/vendor/golang.org/x/net/http2/hpack/encode.go +245 -0
  243. slidge_whatsapp/vendor/golang.org/x/net/http2/hpack/hpack.go +523 -0
  244. slidge_whatsapp/vendor/golang.org/x/net/http2/hpack/huffman.go +226 -0
  245. slidge_whatsapp/vendor/golang.org/x/net/http2/hpack/static_table.go +188 -0
  246. slidge_whatsapp/vendor/golang.org/x/net/http2/hpack/tables.go +403 -0
  247. slidge_whatsapp/vendor/golang.org/x/net/http2/http2.go +432 -0
  248. slidge_whatsapp/vendor/golang.org/x/net/http2/pipe.go +184 -0
  249. slidge_whatsapp/vendor/golang.org/x/net/http2/server.go +3350 -0
  250. slidge_whatsapp/vendor/golang.org/x/net/http2/timer.go +20 -0
  251. slidge_whatsapp/vendor/golang.org/x/net/http2/transport.go +3287 -0
  252. slidge_whatsapp/vendor/golang.org/x/net/http2/unencrypted.go +32 -0
  253. slidge_whatsapp/vendor/golang.org/x/net/http2/write.go +381 -0
  254. slidge_whatsapp/vendor/golang.org/x/net/http2/writesched.go +251 -0
  255. slidge_whatsapp/vendor/golang.org/x/net/http2/writesched_priority.go +451 -0
  256. slidge_whatsapp/vendor/golang.org/x/net/http2/writesched_random.go +77 -0
  257. slidge_whatsapp/vendor/golang.org/x/net/http2/writesched_roundrobin.go +119 -0
  258. slidge_whatsapp/vendor/golang.org/x/net/idna/go118.go +13 -0
  259. slidge_whatsapp/vendor/golang.org/x/net/idna/idna10.0.0.go +769 -0
  260. slidge_whatsapp/vendor/golang.org/x/net/idna/idna9.0.0.go +717 -0
  261. slidge_whatsapp/vendor/golang.org/x/net/idna/pre_go118.go +11 -0
  262. slidge_whatsapp/vendor/golang.org/x/net/idna/punycode.go +217 -0
  263. slidge_whatsapp/vendor/golang.org/x/net/idna/tables10.0.0.go +4559 -0
  264. slidge_whatsapp/vendor/golang.org/x/net/idna/tables11.0.0.go +4653 -0
  265. slidge_whatsapp/vendor/golang.org/x/net/idna/tables12.0.0.go +4733 -0
  266. slidge_whatsapp/vendor/golang.org/x/net/idna/tables13.0.0.go +4959 -0
  267. slidge_whatsapp/vendor/golang.org/x/net/idna/tables15.0.0.go +5144 -0
  268. slidge_whatsapp/vendor/golang.org/x/net/idna/tables9.0.0.go +4486 -0
  269. slidge_whatsapp/vendor/golang.org/x/net/idna/trie.go +51 -0
  270. slidge_whatsapp/vendor/golang.org/x/net/idna/trie12.0.0.go +30 -0
  271. slidge_whatsapp/vendor/golang.org/x/net/idna/trie13.0.0.go +30 -0
  272. slidge_whatsapp/vendor/golang.org/x/net/idna/trieval.go +119 -0
  273. slidge_whatsapp/vendor/golang.org/x/net/internal/httpcommon/ascii.go +53 -0
  274. slidge_whatsapp/vendor/golang.org/x/net/internal/httpcommon/headermap.go +115 -0
  275. slidge_whatsapp/vendor/golang.org/x/net/internal/httpcommon/request.go +467 -0
  276. slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_darwin.go +148 -1
  277. slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_linux.go +16 -26
  278. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +84 -0
  279. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s +20 -0
  280. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +84 -0
  281. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s +20 -0
  282. slidge_whatsapp/vendor/golang.org/x/sys/windows/security_windows.go +44 -5
  283. slidge_whatsapp/vendor/golang.org/x/sys/windows/syscall_windows.go +4 -2
  284. slidge_whatsapp/vendor/golang.org/x/sys/windows/types_windows.go +239 -0
  285. slidge_whatsapp/vendor/golang.org/x/sys/windows/zsyscall_windows.go +9 -0
  286. slidge_whatsapp/vendor/golang.org/x/text/LICENSE +27 -0
  287. slidge_whatsapp/vendor/golang.org/x/text/PATENTS +22 -0
  288. slidge_whatsapp/vendor/golang.org/x/text/secure/bidirule/bidirule.go +336 -0
  289. slidge_whatsapp/vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go +11 -0
  290. slidge_whatsapp/vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go +14 -0
  291. slidge_whatsapp/vendor/golang.org/x/text/transform/transform.go +709 -0
  292. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/bidi.go +359 -0
  293. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/bracket.go +335 -0
  294. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/core.go +1071 -0
  295. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/prop.go +206 -0
  296. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/tables10.0.0.go +1815 -0
  297. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/tables11.0.0.go +1887 -0
  298. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/tables12.0.0.go +1923 -0
  299. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/tables13.0.0.go +1955 -0
  300. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/tables15.0.0.go +2042 -0
  301. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/tables9.0.0.go +1781 -0
  302. slidge_whatsapp/vendor/golang.org/x/text/unicode/bidi/trieval.go +48 -0
  303. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/composition.go +512 -0
  304. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/forminfo.go +279 -0
  305. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/input.go +109 -0
  306. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/iter.go +458 -0
  307. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/normalize.go +610 -0
  308. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/readwriter.go +125 -0
  309. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/tables10.0.0.go +7657 -0
  310. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/tables11.0.0.go +7693 -0
  311. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/tables12.0.0.go +7710 -0
  312. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/tables13.0.0.go +7760 -0
  313. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/tables15.0.0.go +7907 -0
  314. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/tables9.0.0.go +7637 -0
  315. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/transform.go +88 -0
  316. slidge_whatsapp/vendor/golang.org/x/text/unicode/norm/trie.go +54 -0
  317. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb +0 -0
  318. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/filedesc/editions.go +3 -0
  319. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +16 -0
  320. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/strs/{strings_unsafe_go121.go → strings_unsafe.go} +0 -2
  321. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/version/version.go +1 -1
  322. slidge_whatsapp/vendor/google.golang.org/protobuf/proto/merge.go +6 -0
  323. slidge_whatsapp/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +2 -0
  324. slidge_whatsapp/vendor/google.golang.org/protobuf/reflect/protoreflect/{value_unsafe_go121.go → value_unsafe.go} +0 -2
  325. slidge_whatsapp/vendor/modules.txt +52 -13
  326. {slidge_whatsapp-0.2.5.dist-info → slidge_whatsapp-0.2.7.dist-info}/METADATA +1 -1
  327. {slidge_whatsapp-0.2.5.dist-info → slidge_whatsapp-0.2.7.dist-info}/RECORD +330 -184
  328. {slidge_whatsapp-0.2.5.dist-info → slidge_whatsapp-0.2.7.dist-info}/WHEEL +1 -1
  329. slidge_whatsapp/vendor/github.com/rs/zerolog/CNAME +0 -1
  330. slidge_whatsapp/vendor/github.com/rs/zerolog/_config.yml +0 -1
  331. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAdv/WAAdv.pb.raw +0 -0
  332. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloApplication/WAArmadilloApplication.pb.raw +0 -0
  333. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloXMA/WAArmadilloXMA.pb.raw +0 -0
  334. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCert/WACert.pb.raw +0 -23
  335. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waChatLockSettings/WAProtobufsChatLockSettings.pb.raw +0 -7
  336. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCommon/WACommon.pb.raw +0 -0
  337. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WAWebProtobufsCompanionReg.pb.raw +0 -0
  338. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waConsumerApplication/WAConsumerApplication.pb.raw +0 -0
  339. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.pb.raw +0 -0
  340. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.pb.raw +0 -0
  341. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.pb.raw +0 -0
  342. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMediaTransport/WAMediaTransport.pb.raw +0 -0
  343. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMmsRetry/WAMmsRetry.pb.raw +0 -0
  344. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgApplication/WAMsgApplication.pb.raw +0 -0
  345. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgTransport/WAMsgTransport.pb.raw +0 -0
  346. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMultiDevice/WAMultiDevice.pb.raw +0 -0
  347. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waServerSync/WAServerSync.pb.raw +0 -0
  348. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.pb.raw +0 -0
  349. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waUserPassword/WAProtobufsUserPassword.pb.raw +0 -0
  350. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waVnameCert/WAWebProtobufsVnameCert.pb.raw +0 -0
  351. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.pb.raw +0 -0
  352. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.pb.raw +0 -0
  353. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go +0 -296
  354. slidge_whatsapp/vendor/google.golang.org/protobuf/internal/strs/strings_unsafe_go120.go +0 -94
  355. slidge_whatsapp/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go120.go +0 -98
  356. {slidge_whatsapp-0.2.5.dist-info → slidge_whatsapp-0.2.7.dist-info}/LICENSE +0 -0
  357. {slidge_whatsapp-0.2.5.dist-info → slidge_whatsapp-0.2.7.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,1071 @@
1
+ // Copyright 2015 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package bidi
6
+
7
+ import (
8
+ "fmt"
9
+ "log"
10
+ )
11
+
12
+ // This implementation is a port based on the reference implementation found at:
13
+ // https://www.unicode.org/Public/PROGRAMS/BidiReferenceJava/
14
+ //
15
+ // described in Unicode Bidirectional Algorithm (UAX #9).
16
+ //
17
+ // Input:
18
+ // There are two levels of input to the algorithm, since clients may prefer to
19
+ // supply some information from out-of-band sources rather than relying on the
20
+ // default behavior.
21
+ //
22
+ // - Bidi class array
23
+ // - Bidi class array, with externally supplied base line direction
24
+ //
25
+ // Output:
26
+ // Output is separated into several stages:
27
+ //
28
+ // - levels array over entire paragraph
29
+ // - reordering array over entire paragraph
30
+ // - levels array over line
31
+ // - reordering array over line
32
+ //
33
+ // Note that for conformance to the Unicode Bidirectional Algorithm,
34
+ // implementations are only required to generate correct reordering and
35
+ // character directionality (odd or even levels) over a line. Generating
36
+ // identical level arrays over a line is not required. Bidi explicit format
37
+ // codes (LRE, RLE, LRO, RLO, PDF) and BN can be assigned arbitrary levels and
38
+ // positions as long as the rest of the input is properly reordered.
39
+ //
40
+ // As the algorithm is defined to operate on a single paragraph at a time, this
41
+ // implementation is written to handle single paragraphs. Thus rule P1 is
42
+ // presumed by this implementation-- the data provided to the implementation is
43
+ // assumed to be a single paragraph, and either contains no 'B' codes, or a
44
+ // single 'B' code at the end of the input. 'B' is allowed as input to
45
+ // illustrate how the algorithm assigns it a level.
46
+ //
47
+ // Also note that rules L3 and L4 depend on the rendering engine that uses the
48
+ // result of the bidi algorithm. This implementation assumes that the rendering
49
+ // engine expects combining marks in visual order (e.g. to the left of their
50
+ // base character in RTL runs) and that it adjusts the glyphs used to render
51
+ // mirrored characters that are in RTL runs so that they render appropriately.
52
+
53
+ // level is the embedding level of a character. Even embedding levels indicate
54
+ // left-to-right order and odd levels indicate right-to-left order. The special
55
+ // level of -1 is reserved for undefined order.
56
+ type level int8
57
+
58
+ const implicitLevel level = -1
59
+
60
+ // in returns if x is equal to any of the values in set.
61
+ func (c Class) in(set ...Class) bool {
62
+ for _, s := range set {
63
+ if c == s {
64
+ return true
65
+ }
66
+ }
67
+ return false
68
+ }
69
+
70
+ // A paragraph contains the state of a paragraph.
71
+ type paragraph struct {
72
+ initialTypes []Class
73
+
74
+ // Arrays of properties needed for paired bracket evaluation in N0
75
+ pairTypes []bracketType // paired Bracket types for paragraph
76
+ pairValues []rune // rune for opening bracket or pbOpen and pbClose; 0 for pbNone
77
+
78
+ embeddingLevel level // default: = implicitLevel;
79
+
80
+ // at the paragraph levels
81
+ resultTypes []Class
82
+ resultLevels []level
83
+
84
+ // Index of matching PDI for isolate initiator characters. For other
85
+ // characters, the value of matchingPDI will be set to -1. For isolate
86
+ // initiators with no matching PDI, matchingPDI will be set to the length of
87
+ // the input string.
88
+ matchingPDI []int
89
+
90
+ // Index of matching isolate initiator for PDI characters. For other
91
+ // characters, and for PDIs with no matching isolate initiator, the value of
92
+ // matchingIsolateInitiator will be set to -1.
93
+ matchingIsolateInitiator []int
94
+ }
95
+
96
+ // newParagraph initializes a paragraph. The user needs to supply a few arrays
97
+ // corresponding to the preprocessed text input. The types correspond to the
98
+ // Unicode BiDi classes for each rune. pairTypes indicates the bracket type for
99
+ // each rune. pairValues provides a unique bracket class identifier for each
100
+ // rune (suggested is the rune of the open bracket for opening and matching
101
+ // close brackets, after normalization). The embedding levels are optional, but
102
+ // may be supplied to encode embedding levels of styled text.
103
+ func newParagraph(types []Class, pairTypes []bracketType, pairValues []rune, levels level) (*paragraph, error) {
104
+ var err error
105
+ if err = validateTypes(types); err != nil {
106
+ return nil, err
107
+ }
108
+ if err = validatePbTypes(pairTypes); err != nil {
109
+ return nil, err
110
+ }
111
+ if err = validatePbValues(pairValues, pairTypes); err != nil {
112
+ return nil, err
113
+ }
114
+ if err = validateParagraphEmbeddingLevel(levels); err != nil {
115
+ return nil, err
116
+ }
117
+
118
+ p := &paragraph{
119
+ initialTypes: append([]Class(nil), types...),
120
+ embeddingLevel: levels,
121
+
122
+ pairTypes: pairTypes,
123
+ pairValues: pairValues,
124
+
125
+ resultTypes: append([]Class(nil), types...),
126
+ }
127
+ p.run()
128
+ return p, nil
129
+ }
130
+
131
+ func (p *paragraph) Len() int { return len(p.initialTypes) }
132
+
133
+ // The algorithm. Does not include line-based processing (Rules L1, L2).
134
+ // These are applied later in the line-based phase of the algorithm.
135
+ func (p *paragraph) run() {
136
+ p.determineMatchingIsolates()
137
+
138
+ // 1) determining the paragraph level
139
+ // Rule P1 is the requirement for entering this algorithm.
140
+ // Rules P2, P3.
141
+ // If no externally supplied paragraph embedding level, use default.
142
+ if p.embeddingLevel == implicitLevel {
143
+ p.embeddingLevel = p.determineParagraphEmbeddingLevel(0, p.Len())
144
+ }
145
+
146
+ // Initialize result levels to paragraph embedding level.
147
+ p.resultLevels = make([]level, p.Len())
148
+ setLevels(p.resultLevels, p.embeddingLevel)
149
+
150
+ // 2) Explicit levels and directions
151
+ // Rules X1-X8.
152
+ p.determineExplicitEmbeddingLevels()
153
+
154
+ // Rule X9.
155
+ // We do not remove the embeddings, the overrides, the PDFs, and the BNs
156
+ // from the string explicitly. But they are not copied into isolating run
157
+ // sequences when they are created, so they are removed for all
158
+ // practical purposes.
159
+
160
+ // Rule X10.
161
+ // Run remainder of algorithm one isolating run sequence at a time
162
+ for _, seq := range p.determineIsolatingRunSequences() {
163
+ // 3) resolving weak types
164
+ // Rules W1-W7.
165
+ seq.resolveWeakTypes()
166
+
167
+ // 4a) resolving paired brackets
168
+ // Rule N0
169
+ resolvePairedBrackets(seq)
170
+
171
+ // 4b) resolving neutral types
172
+ // Rules N1-N3.
173
+ seq.resolveNeutralTypes()
174
+
175
+ // 5) resolving implicit embedding levels
176
+ // Rules I1, I2.
177
+ seq.resolveImplicitLevels()
178
+
179
+ // Apply the computed levels and types
180
+ seq.applyLevelsAndTypes()
181
+ }
182
+
183
+ // Assign appropriate levels to 'hide' LREs, RLEs, LROs, RLOs, PDFs, and
184
+ // BNs. This is for convenience, so the resulting level array will have
185
+ // a value for every character.
186
+ p.assignLevelsToCharactersRemovedByX9()
187
+ }
188
+
189
+ // determineMatchingIsolates determines the matching PDI for each isolate
190
+ // initiator and vice versa.
191
+ //
192
+ // Definition BD9.
193
+ //
194
+ // At the end of this function:
195
+ //
196
+ // - The member variable matchingPDI is set to point to the index of the
197
+ // matching PDI character for each isolate initiator character. If there is
198
+ // no matching PDI, it is set to the length of the input text. For other
199
+ // characters, it is set to -1.
200
+ // - The member variable matchingIsolateInitiator is set to point to the
201
+ // index of the matching isolate initiator character for each PDI character.
202
+ // If there is no matching isolate initiator, or the character is not a PDI,
203
+ // it is set to -1.
204
+ func (p *paragraph) determineMatchingIsolates() {
205
+ p.matchingPDI = make([]int, p.Len())
206
+ p.matchingIsolateInitiator = make([]int, p.Len())
207
+
208
+ for i := range p.matchingIsolateInitiator {
209
+ p.matchingIsolateInitiator[i] = -1
210
+ }
211
+
212
+ for i := range p.matchingPDI {
213
+ p.matchingPDI[i] = -1
214
+
215
+ if t := p.resultTypes[i]; t.in(LRI, RLI, FSI) {
216
+ depthCounter := 1
217
+ for j := i + 1; j < p.Len(); j++ {
218
+ if u := p.resultTypes[j]; u.in(LRI, RLI, FSI) {
219
+ depthCounter++
220
+ } else if u == PDI {
221
+ if depthCounter--; depthCounter == 0 {
222
+ p.matchingPDI[i] = j
223
+ p.matchingIsolateInitiator[j] = i
224
+ break
225
+ }
226
+ }
227
+ }
228
+ if p.matchingPDI[i] == -1 {
229
+ p.matchingPDI[i] = p.Len()
230
+ }
231
+ }
232
+ }
233
+ }
234
+
235
+ // determineParagraphEmbeddingLevel reports the resolved paragraph direction of
236
+ // the substring limited by the given range [start, end).
237
+ //
238
+ // Determines the paragraph level based on rules P2, P3. This is also used
239
+ // in rule X5c to find if an FSI should resolve to LRI or RLI.
240
+ func (p *paragraph) determineParagraphEmbeddingLevel(start, end int) level {
241
+ var strongType Class = unknownClass
242
+
243
+ // Rule P2.
244
+ for i := start; i < end; i++ {
245
+ if t := p.resultTypes[i]; t.in(L, AL, R) {
246
+ strongType = t
247
+ break
248
+ } else if t.in(FSI, LRI, RLI) {
249
+ i = p.matchingPDI[i] // skip over to the matching PDI
250
+ if i > end {
251
+ log.Panic("assert (i <= end)")
252
+ }
253
+ }
254
+ }
255
+ // Rule P3.
256
+ switch strongType {
257
+ case unknownClass: // none found
258
+ // default embedding level when no strong types found is 0.
259
+ return 0
260
+ case L:
261
+ return 0
262
+ default: // AL, R
263
+ return 1
264
+ }
265
+ }
266
+
267
+ const maxDepth = 125
268
+
269
+ // This stack will store the embedding levels and override and isolated
270
+ // statuses
271
+ type directionalStatusStack struct {
272
+ stackCounter int
273
+ embeddingLevelStack [maxDepth + 1]level
274
+ overrideStatusStack [maxDepth + 1]Class
275
+ isolateStatusStack [maxDepth + 1]bool
276
+ }
277
+
278
+ func (s *directionalStatusStack) empty() { s.stackCounter = 0 }
279
+ func (s *directionalStatusStack) pop() { s.stackCounter-- }
280
+ func (s *directionalStatusStack) depth() int { return s.stackCounter }
281
+
282
+ func (s *directionalStatusStack) push(level level, overrideStatus Class, isolateStatus bool) {
283
+ s.embeddingLevelStack[s.stackCounter] = level
284
+ s.overrideStatusStack[s.stackCounter] = overrideStatus
285
+ s.isolateStatusStack[s.stackCounter] = isolateStatus
286
+ s.stackCounter++
287
+ }
288
+
289
+ func (s *directionalStatusStack) lastEmbeddingLevel() level {
290
+ return s.embeddingLevelStack[s.stackCounter-1]
291
+ }
292
+
293
+ func (s *directionalStatusStack) lastDirectionalOverrideStatus() Class {
294
+ return s.overrideStatusStack[s.stackCounter-1]
295
+ }
296
+
297
+ func (s *directionalStatusStack) lastDirectionalIsolateStatus() bool {
298
+ return s.isolateStatusStack[s.stackCounter-1]
299
+ }
300
+
301
+ // Determine explicit levels using rules X1 - X8
302
+ func (p *paragraph) determineExplicitEmbeddingLevels() {
303
+ var stack directionalStatusStack
304
+ var overflowIsolateCount, overflowEmbeddingCount, validIsolateCount int
305
+
306
+ // Rule X1.
307
+ stack.push(p.embeddingLevel, ON, false)
308
+
309
+ for i, t := range p.resultTypes {
310
+ // Rules X2, X3, X4, X5, X5a, X5b, X5c
311
+ switch t {
312
+ case RLE, LRE, RLO, LRO, RLI, LRI, FSI:
313
+ isIsolate := t.in(RLI, LRI, FSI)
314
+ isRTL := t.in(RLE, RLO, RLI)
315
+
316
+ // override if this is an FSI that resolves to RLI
317
+ if t == FSI {
318
+ isRTL = (p.determineParagraphEmbeddingLevel(i+1, p.matchingPDI[i]) == 1)
319
+ }
320
+ if isIsolate {
321
+ p.resultLevels[i] = stack.lastEmbeddingLevel()
322
+ if stack.lastDirectionalOverrideStatus() != ON {
323
+ p.resultTypes[i] = stack.lastDirectionalOverrideStatus()
324
+ }
325
+ }
326
+
327
+ var newLevel level
328
+ if isRTL {
329
+ // least greater odd
330
+ newLevel = (stack.lastEmbeddingLevel() + 1) | 1
331
+ } else {
332
+ // least greater even
333
+ newLevel = (stack.lastEmbeddingLevel() + 2) &^ 1
334
+ }
335
+
336
+ if newLevel <= maxDepth && overflowIsolateCount == 0 && overflowEmbeddingCount == 0 {
337
+ if isIsolate {
338
+ validIsolateCount++
339
+ }
340
+ // Push new embedding level, override status, and isolated
341
+ // status.
342
+ // No check for valid stack counter, since the level check
343
+ // suffices.
344
+ switch t {
345
+ case LRO:
346
+ stack.push(newLevel, L, isIsolate)
347
+ case RLO:
348
+ stack.push(newLevel, R, isIsolate)
349
+ default:
350
+ stack.push(newLevel, ON, isIsolate)
351
+ }
352
+ // Not really part of the spec
353
+ if !isIsolate {
354
+ p.resultLevels[i] = newLevel
355
+ }
356
+ } else {
357
+ // This is an invalid explicit formatting character,
358
+ // so apply the "Otherwise" part of rules X2-X5b.
359
+ if isIsolate {
360
+ overflowIsolateCount++
361
+ } else { // !isIsolate
362
+ if overflowIsolateCount == 0 {
363
+ overflowEmbeddingCount++
364
+ }
365
+ }
366
+ }
367
+
368
+ // Rule X6a
369
+ case PDI:
370
+ if overflowIsolateCount > 0 {
371
+ overflowIsolateCount--
372
+ } else if validIsolateCount == 0 {
373
+ // do nothing
374
+ } else {
375
+ overflowEmbeddingCount = 0
376
+ for !stack.lastDirectionalIsolateStatus() {
377
+ stack.pop()
378
+ }
379
+ stack.pop()
380
+ validIsolateCount--
381
+ }
382
+ p.resultLevels[i] = stack.lastEmbeddingLevel()
383
+
384
+ // Rule X7
385
+ case PDF:
386
+ // Not really part of the spec
387
+ p.resultLevels[i] = stack.lastEmbeddingLevel()
388
+
389
+ if overflowIsolateCount > 0 {
390
+ // do nothing
391
+ } else if overflowEmbeddingCount > 0 {
392
+ overflowEmbeddingCount--
393
+ } else if !stack.lastDirectionalIsolateStatus() && stack.depth() >= 2 {
394
+ stack.pop()
395
+ }
396
+
397
+ case B: // paragraph separator.
398
+ // Rule X8.
399
+
400
+ // These values are reset for clarity, in this implementation B
401
+ // can only occur as the last code in the array.
402
+ stack.empty()
403
+ overflowIsolateCount = 0
404
+ overflowEmbeddingCount = 0
405
+ validIsolateCount = 0
406
+ p.resultLevels[i] = p.embeddingLevel
407
+
408
+ default:
409
+ p.resultLevels[i] = stack.lastEmbeddingLevel()
410
+ if stack.lastDirectionalOverrideStatus() != ON {
411
+ p.resultTypes[i] = stack.lastDirectionalOverrideStatus()
412
+ }
413
+ }
414
+ }
415
+ }
416
+
417
+ type isolatingRunSequence struct {
418
+ p *paragraph
419
+
420
+ indexes []int // indexes to the original string
421
+
422
+ types []Class // type of each character using the index
423
+ resolvedLevels []level // resolved levels after application of rules
424
+ level level
425
+ sos, eos Class
426
+ }
427
+
428
+ func (i *isolatingRunSequence) Len() int { return len(i.indexes) }
429
+
430
+ func maxLevel(a, b level) level {
431
+ if a > b {
432
+ return a
433
+ }
434
+ return b
435
+ }
436
+
437
+ // Rule X10, second bullet: Determine the start-of-sequence (sos) and end-of-sequence (eos) types,
438
+ // either L or R, for each isolating run sequence.
439
+ func (p *paragraph) isolatingRunSequence(indexes []int) *isolatingRunSequence {
440
+ length := len(indexes)
441
+ types := make([]Class, length)
442
+ for i, x := range indexes {
443
+ types[i] = p.resultTypes[x]
444
+ }
445
+
446
+ // assign level, sos and eos
447
+ prevChar := indexes[0] - 1
448
+ for prevChar >= 0 && isRemovedByX9(p.initialTypes[prevChar]) {
449
+ prevChar--
450
+ }
451
+ prevLevel := p.embeddingLevel
452
+ if prevChar >= 0 {
453
+ prevLevel = p.resultLevels[prevChar]
454
+ }
455
+
456
+ var succLevel level
457
+ lastType := types[length-1]
458
+ if lastType.in(LRI, RLI, FSI) {
459
+ succLevel = p.embeddingLevel
460
+ } else {
461
+ // the first character after the end of run sequence
462
+ limit := indexes[length-1] + 1
463
+ for ; limit < p.Len() && isRemovedByX9(p.initialTypes[limit]); limit++ {
464
+
465
+ }
466
+ succLevel = p.embeddingLevel
467
+ if limit < p.Len() {
468
+ succLevel = p.resultLevels[limit]
469
+ }
470
+ }
471
+ level := p.resultLevels[indexes[0]]
472
+ return &isolatingRunSequence{
473
+ p: p,
474
+ indexes: indexes,
475
+ types: types,
476
+ level: level,
477
+ sos: typeForLevel(maxLevel(prevLevel, level)),
478
+ eos: typeForLevel(maxLevel(succLevel, level)),
479
+ }
480
+ }
481
+
482
+ // Resolving weak types Rules W1-W7.
483
+ //
484
+ // Note that some weak types (EN, AN) remain after this processing is
485
+ // complete.
486
+ func (s *isolatingRunSequence) resolveWeakTypes() {
487
+
488
+ // on entry, only these types remain
489
+ s.assertOnly(L, R, AL, EN, ES, ET, AN, CS, B, S, WS, ON, NSM, LRI, RLI, FSI, PDI)
490
+
491
+ // Rule W1.
492
+ // Changes all NSMs.
493
+ precedingCharacterType := s.sos
494
+ for i, t := range s.types {
495
+ if t == NSM {
496
+ s.types[i] = precedingCharacterType
497
+ } else {
498
+ // if t.in(LRI, RLI, FSI, PDI) {
499
+ // precedingCharacterType = ON
500
+ // }
501
+ precedingCharacterType = t
502
+ }
503
+ }
504
+
505
+ // Rule W2.
506
+ // EN does not change at the start of the run, because sos != AL.
507
+ for i, t := range s.types {
508
+ if t == EN {
509
+ for j := i - 1; j >= 0; j-- {
510
+ if t := s.types[j]; t.in(L, R, AL) {
511
+ if t == AL {
512
+ s.types[i] = AN
513
+ }
514
+ break
515
+ }
516
+ }
517
+ }
518
+ }
519
+
520
+ // Rule W3.
521
+ for i, t := range s.types {
522
+ if t == AL {
523
+ s.types[i] = R
524
+ }
525
+ }
526
+
527
+ // Rule W4.
528
+ // Since there must be values on both sides for this rule to have an
529
+ // effect, the scan skips the first and last value.
530
+ //
531
+ // Although the scan proceeds left to right, and changes the type
532
+ // values in a way that would appear to affect the computations
533
+ // later in the scan, there is actually no problem. A change in the
534
+ // current value can only affect the value to its immediate right,
535
+ // and only affect it if it is ES or CS. But the current value can
536
+ // only change if the value to its right is not ES or CS. Thus
537
+ // either the current value will not change, or its change will have
538
+ // no effect on the remainder of the analysis.
539
+
540
+ for i := 1; i < s.Len()-1; i++ {
541
+ t := s.types[i]
542
+ if t == ES || t == CS {
543
+ prevSepType := s.types[i-1]
544
+ succSepType := s.types[i+1]
545
+ if prevSepType == EN && succSepType == EN {
546
+ s.types[i] = EN
547
+ } else if s.types[i] == CS && prevSepType == AN && succSepType == AN {
548
+ s.types[i] = AN
549
+ }
550
+ }
551
+ }
552
+
553
+ // Rule W5.
554
+ for i, t := range s.types {
555
+ if t == ET {
556
+ // locate end of sequence
557
+ runStart := i
558
+ runEnd := s.findRunLimit(runStart, ET)
559
+
560
+ // check values at ends of sequence
561
+ t := s.sos
562
+ if runStart > 0 {
563
+ t = s.types[runStart-1]
564
+ }
565
+ if t != EN {
566
+ t = s.eos
567
+ if runEnd < len(s.types) {
568
+ t = s.types[runEnd]
569
+ }
570
+ }
571
+ if t == EN {
572
+ setTypes(s.types[runStart:runEnd], EN)
573
+ }
574
+ // continue at end of sequence
575
+ i = runEnd
576
+ }
577
+ }
578
+
579
+ // Rule W6.
580
+ for i, t := range s.types {
581
+ if t.in(ES, ET, CS) {
582
+ s.types[i] = ON
583
+ }
584
+ }
585
+
586
+ // Rule W7.
587
+ for i, t := range s.types {
588
+ if t == EN {
589
+ // set default if we reach start of run
590
+ prevStrongType := s.sos
591
+ for j := i - 1; j >= 0; j-- {
592
+ t = s.types[j]
593
+ if t == L || t == R { // AL's have been changed to R
594
+ prevStrongType = t
595
+ break
596
+ }
597
+ }
598
+ if prevStrongType == L {
599
+ s.types[i] = L
600
+ }
601
+ }
602
+ }
603
+ }
604
+
605
+ // 6) resolving neutral types Rules N1-N2.
606
+ func (s *isolatingRunSequence) resolveNeutralTypes() {
607
+
608
+ // on entry, only these types can be in resultTypes
609
+ s.assertOnly(L, R, EN, AN, B, S, WS, ON, RLI, LRI, FSI, PDI)
610
+
611
+ for i, t := range s.types {
612
+ switch t {
613
+ case WS, ON, B, S, RLI, LRI, FSI, PDI:
614
+ // find bounds of run of neutrals
615
+ runStart := i
616
+ runEnd := s.findRunLimit(runStart, B, S, WS, ON, RLI, LRI, FSI, PDI)
617
+
618
+ // determine effective types at ends of run
619
+ var leadType, trailType Class
620
+
621
+ // Note that the character found can only be L, R, AN, or
622
+ // EN.
623
+ if runStart == 0 {
624
+ leadType = s.sos
625
+ } else {
626
+ leadType = s.types[runStart-1]
627
+ if leadType.in(AN, EN) {
628
+ leadType = R
629
+ }
630
+ }
631
+ if runEnd == len(s.types) {
632
+ trailType = s.eos
633
+ } else {
634
+ trailType = s.types[runEnd]
635
+ if trailType.in(AN, EN) {
636
+ trailType = R
637
+ }
638
+ }
639
+
640
+ var resolvedType Class
641
+ if leadType == trailType {
642
+ // Rule N1.
643
+ resolvedType = leadType
644
+ } else {
645
+ // Rule N2.
646
+ // Notice the embedding level of the run is used, not
647
+ // the paragraph embedding level.
648
+ resolvedType = typeForLevel(s.level)
649
+ }
650
+
651
+ setTypes(s.types[runStart:runEnd], resolvedType)
652
+
653
+ // skip over run of (former) neutrals
654
+ i = runEnd
655
+ }
656
+ }
657
+ }
658
+
659
+ func setLevels(levels []level, newLevel level) {
660
+ for i := range levels {
661
+ levels[i] = newLevel
662
+ }
663
+ }
664
+
665
+ func setTypes(types []Class, newType Class) {
666
+ for i := range types {
667
+ types[i] = newType
668
+ }
669
+ }
670
+
671
+ // 7) resolving implicit embedding levels Rules I1, I2.
672
+ func (s *isolatingRunSequence) resolveImplicitLevels() {
673
+
674
+ // on entry, only these types can be in resultTypes
675
+ s.assertOnly(L, R, EN, AN)
676
+
677
+ s.resolvedLevels = make([]level, len(s.types))
678
+ setLevels(s.resolvedLevels, s.level)
679
+
680
+ if (s.level & 1) == 0 { // even level
681
+ for i, t := range s.types {
682
+ // Rule I1.
683
+ if t == L {
684
+ // no change
685
+ } else if t == R {
686
+ s.resolvedLevels[i] += 1
687
+ } else { // t == AN || t == EN
688
+ s.resolvedLevels[i] += 2
689
+ }
690
+ }
691
+ } else { // odd level
692
+ for i, t := range s.types {
693
+ // Rule I2.
694
+ if t == R {
695
+ // no change
696
+ } else { // t == L || t == AN || t == EN
697
+ s.resolvedLevels[i] += 1
698
+ }
699
+ }
700
+ }
701
+ }
702
+
703
+ // Applies the levels and types resolved in rules W1-I2 to the
704
+ // resultLevels array.
705
+ func (s *isolatingRunSequence) applyLevelsAndTypes() {
706
+ for i, x := range s.indexes {
707
+ s.p.resultTypes[x] = s.types[i]
708
+ s.p.resultLevels[x] = s.resolvedLevels[i]
709
+ }
710
+ }
711
+
712
+ // Return the limit of the run consisting only of the types in validSet
713
+ // starting at index. This checks the value at index, and will return
714
+ // index if that value is not in validSet.
715
+ func (s *isolatingRunSequence) findRunLimit(index int, validSet ...Class) int {
716
+ loop:
717
+ for ; index < len(s.types); index++ {
718
+ t := s.types[index]
719
+ for _, valid := range validSet {
720
+ if t == valid {
721
+ continue loop
722
+ }
723
+ }
724
+ return index // didn't find a match in validSet
725
+ }
726
+ return len(s.types)
727
+ }
728
+
729
+ // Algorithm validation. Assert that all values in types are in the
730
+ // provided set.
731
+ func (s *isolatingRunSequence) assertOnly(codes ...Class) {
732
+ loop:
733
+ for i, t := range s.types {
734
+ for _, c := range codes {
735
+ if t == c {
736
+ continue loop
737
+ }
738
+ }
739
+ log.Panicf("invalid bidi code %v present in assertOnly at position %d", t, s.indexes[i])
740
+ }
741
+ }
742
+
743
+ // determineLevelRuns returns an array of level runs. Each level run is
744
+ // described as an array of indexes into the input string.
745
+ //
746
+ // Determines the level runs. Rule X9 will be applied in determining the
747
+ // runs, in the way that makes sure the characters that are supposed to be
748
+ // removed are not included in the runs.
749
+ func (p *paragraph) determineLevelRuns() [][]int {
750
+ run := []int{}
751
+ allRuns := [][]int{}
752
+ currentLevel := implicitLevel
753
+
754
+ for i := range p.initialTypes {
755
+ if !isRemovedByX9(p.initialTypes[i]) {
756
+ if p.resultLevels[i] != currentLevel {
757
+ // we just encountered a new run; wrap up last run
758
+ if currentLevel >= 0 { // only wrap it up if there was a run
759
+ allRuns = append(allRuns, run)
760
+ run = nil
761
+ }
762
+ // Start new run
763
+ currentLevel = p.resultLevels[i]
764
+ }
765
+ run = append(run, i)
766
+ }
767
+ }
768
+ // Wrap up the final run, if any
769
+ if len(run) > 0 {
770
+ allRuns = append(allRuns, run)
771
+ }
772
+ return allRuns
773
+ }
774
+
775
+ // Definition BD13. Determine isolating run sequences.
776
+ func (p *paragraph) determineIsolatingRunSequences() []*isolatingRunSequence {
777
+ levelRuns := p.determineLevelRuns()
778
+
779
+ // Compute the run that each character belongs to
780
+ runForCharacter := make([]int, p.Len())
781
+ for i, run := range levelRuns {
782
+ for _, index := range run {
783
+ runForCharacter[index] = i
784
+ }
785
+ }
786
+
787
+ sequences := []*isolatingRunSequence{}
788
+
789
+ var currentRunSequence []int
790
+
791
+ for _, run := range levelRuns {
792
+ first := run[0]
793
+ if p.initialTypes[first] != PDI || p.matchingIsolateInitiator[first] == -1 {
794
+ currentRunSequence = nil
795
+ // int run = i;
796
+ for {
797
+ // Copy this level run into currentRunSequence
798
+ currentRunSequence = append(currentRunSequence, run...)
799
+
800
+ last := currentRunSequence[len(currentRunSequence)-1]
801
+ lastT := p.initialTypes[last]
802
+ if lastT.in(LRI, RLI, FSI) && p.matchingPDI[last] != p.Len() {
803
+ run = levelRuns[runForCharacter[p.matchingPDI[last]]]
804
+ } else {
805
+ break
806
+ }
807
+ }
808
+ sequences = append(sequences, p.isolatingRunSequence(currentRunSequence))
809
+ }
810
+ }
811
+ return sequences
812
+ }
813
+
814
+ // Assign level information to characters removed by rule X9. This is for
815
+ // ease of relating the level information to the original input data. Note
816
+ // that the levels assigned to these codes are arbitrary, they're chosen so
817
+ // as to avoid breaking level runs.
818
+ func (p *paragraph) assignLevelsToCharactersRemovedByX9() {
819
+ for i, t := range p.initialTypes {
820
+ if t.in(LRE, RLE, LRO, RLO, PDF, BN) {
821
+ p.resultTypes[i] = t
822
+ p.resultLevels[i] = -1
823
+ }
824
+ }
825
+ // now propagate forward the levels information (could have
826
+ // propagated backward, the main thing is not to introduce a level
827
+ // break where one doesn't already exist).
828
+
829
+ if p.resultLevels[0] == -1 {
830
+ p.resultLevels[0] = p.embeddingLevel
831
+ }
832
+ for i := 1; i < len(p.initialTypes); i++ {
833
+ if p.resultLevels[i] == -1 {
834
+ p.resultLevels[i] = p.resultLevels[i-1]
835
+ }
836
+ }
837
+ // Embedding information is for informational purposes only so need not be
838
+ // adjusted.
839
+ }
840
+
841
+ //
842
+ // Output
843
+ //
844
+
845
+ // getLevels computes levels array breaking lines at offsets in linebreaks.
846
+ // Rule L1.
847
+ //
848
+ // The linebreaks array must include at least one value. The values must be
849
+ // in strictly increasing order (no duplicates) between 1 and the length of
850
+ // the text, inclusive. The last value must be the length of the text.
851
+ func (p *paragraph) getLevels(linebreaks []int) []level {
852
+ // Note that since the previous processing has removed all
853
+ // P, S, and WS values from resultTypes, the values referred to
854
+ // in these rules are the initial types, before any processing
855
+ // has been applied (including processing of overrides).
856
+ //
857
+ // This example implementation has reinserted explicit format codes
858
+ // and BN, in order that the levels array correspond to the
859
+ // initial text. Their final placement is not normative.
860
+ // These codes are treated like WS in this implementation,
861
+ // so they don't interrupt sequences of WS.
862
+
863
+ validateLineBreaks(linebreaks, p.Len())
864
+
865
+ result := append([]level(nil), p.resultLevels...)
866
+
867
+ // don't worry about linebreaks since if there is a break within
868
+ // a series of WS values preceding S, the linebreak itself
869
+ // causes the reset.
870
+ for i, t := range p.initialTypes {
871
+ if t.in(B, S) {
872
+ // Rule L1, clauses one and two.
873
+ result[i] = p.embeddingLevel
874
+
875
+ // Rule L1, clause three.
876
+ for j := i - 1; j >= 0; j-- {
877
+ if isWhitespace(p.initialTypes[j]) { // including format codes
878
+ result[j] = p.embeddingLevel
879
+ } else {
880
+ break
881
+ }
882
+ }
883
+ }
884
+ }
885
+
886
+ // Rule L1, clause four.
887
+ start := 0
888
+ for _, limit := range linebreaks {
889
+ for j := limit - 1; j >= start; j-- {
890
+ if isWhitespace(p.initialTypes[j]) { // including format codes
891
+ result[j] = p.embeddingLevel
892
+ } else {
893
+ break
894
+ }
895
+ }
896
+ start = limit
897
+ }
898
+
899
+ return result
900
+ }
901
+
902
+ // getReordering returns the reordering of lines from a visual index to a
903
+ // logical index for line breaks at the given offsets.
904
+ //
905
+ // Lines are concatenated from left to right. So for example, the fifth
906
+ // character from the left on the third line is
907
+ //
908
+ // getReordering(linebreaks)[linebreaks[1] + 4]
909
+ //
910
+ // (linebreaks[1] is the position after the last character of the second
911
+ // line, which is also the index of the first character on the third line,
912
+ // and adding four gets the fifth character from the left).
913
+ //
914
+ // The linebreaks array must include at least one value. The values must be
915
+ // in strictly increasing order (no duplicates) between 1 and the length of
916
+ // the text, inclusive. The last value must be the length of the text.
917
+ func (p *paragraph) getReordering(linebreaks []int) []int {
918
+ validateLineBreaks(linebreaks, p.Len())
919
+
920
+ return computeMultilineReordering(p.getLevels(linebreaks), linebreaks)
921
+ }
922
+
923
+ // Return multiline reordering array for a given level array. Reordering
924
+ // does not occur across a line break.
925
+ func computeMultilineReordering(levels []level, linebreaks []int) []int {
926
+ result := make([]int, len(levels))
927
+
928
+ start := 0
929
+ for _, limit := range linebreaks {
930
+ tempLevels := make([]level, limit-start)
931
+ copy(tempLevels, levels[start:])
932
+
933
+ for j, order := range computeReordering(tempLevels) {
934
+ result[start+j] = order + start
935
+ }
936
+ start = limit
937
+ }
938
+ return result
939
+ }
940
+
941
+ // Return reordering array for a given level array. This reorders a single
942
+ // line. The reordering is a visual to logical map. For example, the
943
+ // leftmost char is string.charAt(order[0]). Rule L2.
944
+ func computeReordering(levels []level) []int {
945
+ result := make([]int, len(levels))
946
+ // initialize order
947
+ for i := range result {
948
+ result[i] = i
949
+ }
950
+
951
+ // locate highest level found on line.
952
+ // Note the rules say text, but no reordering across line bounds is
953
+ // performed, so this is sufficient.
954
+ highestLevel := level(0)
955
+ lowestOddLevel := level(maxDepth + 2)
956
+ for _, level := range levels {
957
+ if level > highestLevel {
958
+ highestLevel = level
959
+ }
960
+ if level&1 != 0 && level < lowestOddLevel {
961
+ lowestOddLevel = level
962
+ }
963
+ }
964
+
965
+ for level := highestLevel; level >= lowestOddLevel; level-- {
966
+ for i := 0; i < len(levels); i++ {
967
+ if levels[i] >= level {
968
+ // find range of text at or above this level
969
+ start := i
970
+ limit := i + 1
971
+ for limit < len(levels) && levels[limit] >= level {
972
+ limit++
973
+ }
974
+
975
+ for j, k := start, limit-1; j < k; j, k = j+1, k-1 {
976
+ result[j], result[k] = result[k], result[j]
977
+ }
978
+ // skip to end of level run
979
+ i = limit
980
+ }
981
+ }
982
+ }
983
+
984
+ return result
985
+ }
986
+
987
+ // isWhitespace reports whether the type is considered a whitespace type for the
988
+ // line break rules.
989
+ func isWhitespace(c Class) bool {
990
+ switch c {
991
+ case LRE, RLE, LRO, RLO, PDF, LRI, RLI, FSI, PDI, BN, WS:
992
+ return true
993
+ }
994
+ return false
995
+ }
996
+
997
+ // isRemovedByX9 reports whether the type is one of the types removed in X9.
998
+ func isRemovedByX9(c Class) bool {
999
+ switch c {
1000
+ case LRE, RLE, LRO, RLO, PDF, BN:
1001
+ return true
1002
+ }
1003
+ return false
1004
+ }
1005
+
1006
+ // typeForLevel reports the strong type (L or R) corresponding to the level.
1007
+ func typeForLevel(level level) Class {
1008
+ if (level & 0x1) == 0 {
1009
+ return L
1010
+ }
1011
+ return R
1012
+ }
1013
+
1014
+ func validateTypes(types []Class) error {
1015
+ if len(types) == 0 {
1016
+ return fmt.Errorf("types is null")
1017
+ }
1018
+ for i, t := range types[:len(types)-1] {
1019
+ if t == B {
1020
+ return fmt.Errorf("B type before end of paragraph at index: %d", i)
1021
+ }
1022
+ }
1023
+ return nil
1024
+ }
1025
+
1026
+ func validateParagraphEmbeddingLevel(embeddingLevel level) error {
1027
+ if embeddingLevel != implicitLevel &&
1028
+ embeddingLevel != 0 &&
1029
+ embeddingLevel != 1 {
1030
+ return fmt.Errorf("illegal paragraph embedding level: %d", embeddingLevel)
1031
+ }
1032
+ return nil
1033
+ }
1034
+
1035
+ func validateLineBreaks(linebreaks []int, textLength int) error {
1036
+ prev := 0
1037
+ for i, next := range linebreaks {
1038
+ if next <= prev {
1039
+ return fmt.Errorf("bad linebreak: %d at index: %d", next, i)
1040
+ }
1041
+ prev = next
1042
+ }
1043
+ if prev != textLength {
1044
+ return fmt.Errorf("last linebreak was %d, want %d", prev, textLength)
1045
+ }
1046
+ return nil
1047
+ }
1048
+
1049
+ func validatePbTypes(pairTypes []bracketType) error {
1050
+ if len(pairTypes) == 0 {
1051
+ return fmt.Errorf("pairTypes is null")
1052
+ }
1053
+ for i, pt := range pairTypes {
1054
+ switch pt {
1055
+ case bpNone, bpOpen, bpClose:
1056
+ default:
1057
+ return fmt.Errorf("illegal pairType value at %d: %v", i, pairTypes[i])
1058
+ }
1059
+ }
1060
+ return nil
1061
+ }
1062
+
1063
+ func validatePbValues(pairValues []rune, pairTypes []bracketType) error {
1064
+ if pairValues == nil {
1065
+ return fmt.Errorf("pairValues is null")
1066
+ }
1067
+ if len(pairTypes) != len(pairValues) {
1068
+ return fmt.Errorf("pairTypes is different length from pairValues")
1069
+ }
1070
+ return nil
1071
+ }