diff options
Diffstat (limited to 'vendor/iana-time-zone')
-rw-r--r-- | vendor/iana-time-zone/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/iana-time-zone/CHANGELOG.md | 4 | ||||
-rw-r--r-- | vendor/iana-time-zone/Cargo.lock | 207 | ||||
-rw-r--r-- | vendor/iana-time-zone/Cargo.toml | 2 | ||||
-rw-r--r-- | vendor/iana-time-zone/src/platform.rs | 2 | ||||
-rw-r--r-- | vendor/iana-time-zone/src/tz_linux.rs | 141 |
6 files changed, 191 insertions, 167 deletions
diff --git a/vendor/iana-time-zone/.cargo-checksum.json b/vendor/iana-time-zone/.cargo-checksum.json index 1ff051c20..356725a06 100644 --- a/vendor/iana-time-zone/.cargo-checksum.json +++ b/vendor/iana-time-zone/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"CHANGELOG.md":"6002d865cdaa676f19ab808b8545bb1e8993a6778e549a6ea187dd3dc743baa9","Cargo.lock":"c4aa3f484b70d79c93718b0118d0fdd175d2737a1756e5e4cb80fa17c0aaecac","Cargo.toml":"d05222cc7ad10943b33bc95d7e6e116dd9689a3e498909257c460ce5090f2038","LICENSE-APACHE":"696759d65dfe558ff7d9f031c76db19ec5c0767470fb67c4e8d990820d1e99c9","LICENSE-MIT":"da28ccc6b158fc2d8cccc74e99794b1cff1d29bd7bbeb019442fcf0c04c6cad9","README.md":"c5531c44131c4b4473a747d6eab8868d31964da70af6264650253212df5ba9f4","examples/get_timezone.rs":"c4db7b1cc71c7b3728ddd70e76c0dbd40239c6b1b8c705cb63476757d3177dec","examples/stress-test.rs":"3ad469de5a650389699c9ffe5fd78af2bdd46e7140cc05391c60d793fc6f8e98","src/ffi_utils.rs":"bfbd155b004c2fc4e793aec4604c7b353f71caf35bf67e9b34cd07349628571f","src/lib.rs":"ed60b3581f02879544d87be98764f439676a1b88da7d927c7ec4a785295ec114","src/platform.rs":"bef2c3ead64d498cefedc2555194bb492db06e3d49423bdcdec5f6c5696cf091","src/tz_android.rs":"3da37f1b87f87a0ed215734f2b373b2d187bcf49386adfe8bfff207f9a5e8fe2","src/tz_freebsd.rs":"4247af5c6dd0712705186ed54d789193c64139f707af316d4fde86aa1e2a1b13","src/tz_haiku.rs":"761afd80301683a44bf937bbf6b13c5c792af42ed7037623bbeccbab6d0aa8fc","src/tz_illumos.rs":"375ae951d1417f63e6d77c9add7f7f646f24c0054cb8407bd4b9f06907494888","src/tz_linux.rs":"7bbc921fcbc71d87c5527b45f7d44963fcef5a6f2a015b78a858cf441c9e1727","src/tz_macos.rs":"081d5e60955268a1b6949089354eb6657de1c2eb569a69f4e094b995270d540d","src/tz_netbsd.rs":"ec278bbe1cb5f648c063ec23bff6081146454b9f6aa3918b9ca50b8804d5838f","src/tz_wasm32.rs":"10aa33caa86645a16e2126fe1a86dda2b57f63caa9addcd726245fbc9657dc1b","src/tz_windows.rs":"9cafe592b28505c9d2bb9adfb2924c877f1fc2685ee2be2b1e68ed45f64553f1"},"package":"0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"}
\ No newline at end of file +{"files":{"CHANGELOG.md":"93004e88d2fd9de0e3ade9be46ff05ce1831d82429894bb92a9fa7d17982885f","Cargo.lock":"b18d1c32cd6a0933a4b86f163a2f46e115716076978c38121933d472e7239f1e","Cargo.toml":"d30a9e40142079ee0d529522f2912604f4679c80d61bdecdf840ec338d245ebf","LICENSE-APACHE":"696759d65dfe558ff7d9f031c76db19ec5c0767470fb67c4e8d990820d1e99c9","LICENSE-MIT":"da28ccc6b158fc2d8cccc74e99794b1cff1d29bd7bbeb019442fcf0c04c6cad9","README.md":"c5531c44131c4b4473a747d6eab8868d31964da70af6264650253212df5ba9f4","examples/get_timezone.rs":"c4db7b1cc71c7b3728ddd70e76c0dbd40239c6b1b8c705cb63476757d3177dec","examples/stress-test.rs":"3ad469de5a650389699c9ffe5fd78af2bdd46e7140cc05391c60d793fc6f8e98","src/ffi_utils.rs":"bfbd155b004c2fc4e793aec4604c7b353f71caf35bf67e9b34cd07349628571f","src/lib.rs":"ed60b3581f02879544d87be98764f439676a1b88da7d927c7ec4a785295ec114","src/platform.rs":"1748faef9b3f42f12b882d7e67e3792096400dc83fee024d85457aae668558f8","src/tz_android.rs":"3da37f1b87f87a0ed215734f2b373b2d187bcf49386adfe8bfff207f9a5e8fe2","src/tz_freebsd.rs":"4247af5c6dd0712705186ed54d789193c64139f707af316d4fde86aa1e2a1b13","src/tz_haiku.rs":"761afd80301683a44bf937bbf6b13c5c792af42ed7037623bbeccbab6d0aa8fc","src/tz_illumos.rs":"375ae951d1417f63e6d77c9add7f7f646f24c0054cb8407bd4b9f06907494888","src/tz_linux.rs":"3f04dbc1345ef6783881f3ff9aef4449819dbdc8a1578ffad69c03dc65623f9a","src/tz_macos.rs":"081d5e60955268a1b6949089354eb6657de1c2eb569a69f4e094b995270d540d","src/tz_netbsd.rs":"ec278bbe1cb5f648c063ec23bff6081146454b9f6aa3918b9ca50b8804d5838f","src/tz_wasm32.rs":"10aa33caa86645a16e2126fe1a86dda2b57f63caa9addcd726245fbc9657dc1b","src/tz_windows.rs":"9cafe592b28505c9d2bb9adfb2924c877f1fc2685ee2be2b1e68ed45f64553f1"},"package":"2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"}
\ No newline at end of file diff --git a/vendor/iana-time-zone/CHANGELOG.md b/vendor/iana-time-zone/CHANGELOG.md index 81159ca28..588e76111 100644 --- a/vendor/iana-time-zone/CHANGELOG.md +++ b/vendor/iana-time-zone/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.57] - 2023-06-07 +### Changed +- implement OpenWRT support ([#109](https://github.com/strawlab/iana-time-zone/pull/109)) + ## [0.1.56] - 2023-04-03 ### Changed - update `windows` dependency ([#102](https://github.com/strawlab/iana-time-zone/pull/102)) diff --git a/vendor/iana-time-zone/Cargo.lock b/vendor/iana-time-zone/Cargo.lock index b5d89dc35..18c3350bd 100644 --- a/vendor/iana-time-zone/Cargo.lock +++ b/vendor/iana-time-zone/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "cc" @@ -30,16 +30,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - -[[package]] name = "console_error_panic_hook" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -51,57 +41,13 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - -[[package]] -name = "cxx" -version = "1.0.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.92" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "iana-time-zone" -version = "0.1.56" +version = "0.1.57" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -114,88 +60,69 @@ dependencies = [ [[package]] name = "iana-time-zone-haiku" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" dependencies = [ - "cxx", - "cxx-build", + "cc", ] [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.132" +version = "0.2.146" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" - -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] +checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" [[package]] name = "log" -version = "0.4.17" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" [[package]] name = "once_cell" -version = "1.14.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] [[package]] name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - -[[package]] -name = "scratch" -version = "1.0.5" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] name = "syn" -version = "1.0.99" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" dependencies = [ "proc-macro2", "quote", @@ -203,31 +130,16 @@ dependencies = [ ] [[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - -[[package]] name = "unicode-ident" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" - -[[package]] -name = "unicode-width" -version = "0.1.10" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -235,9 +147,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" dependencies = [ "bumpalo", "log", @@ -250,9 +162,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.33" +version = "0.4.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e" dependencies = [ "cfg-if", "js-sys", @@ -262,9 +174,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -272,9 +184,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" dependencies = [ "proc-macro2", "quote", @@ -285,15 +197,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" [[package]] name = "wasm-bindgen-test" -version = "0.3.33" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d2fff962180c3fadf677438054b1db62bee4aa32af26a45388af07d1287e1d" +checksum = "c9e636f3a428ff62b3742ebc3c70e254dfe12b8c2b469d688ea59cdd4abcf502" dependencies = [ "console_error_panic_hook", "js-sys", @@ -305,9 +217,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.33" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4683da3dfc016f704c9f82cf401520c4f1cb3ee440f7f52b3d6ac29506a49ca7" +checksum = "f18c1fad2f7c4958e7bcce014fa212f59a65d5e3721d0f77e6c0b27ede936ba3" dependencies = [ "proc-macro2", "quote", @@ -315,46 +227,15 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] name = "windows" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/vendor/iana-time-zone/Cargo.toml b/vendor/iana-time-zone/Cargo.toml index 5cdc175a7..e06c7055b 100644 --- a/vendor/iana-time-zone/Cargo.toml +++ b/vendor/iana-time-zone/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "iana-time-zone" -version = "0.1.56" +version = "0.1.57" authors = [ "Andrew Straw <strawman@astraw.com>", "René Kijewski <rene.kijewski@fu-berlin.de>", diff --git a/vendor/iana-time-zone/src/platform.rs b/vendor/iana-time-zone/src/platform.rs index 5992bf377..d5ba0ee34 100644 --- a/vendor/iana-time-zone/src/platform.rs +++ b/vendor/iana-time-zone/src/platform.rs @@ -1,4 +1,4 @@ -pub fn get_timezone_inner() -> std::result::Result<String, crate::GetTimezoneError> { +pub fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> { Err(crate::GetTimezoneError::OsError) } diff --git a/vendor/iana-time-zone/src/tz_linux.rs b/vendor/iana-time-zone/src/tz_linux.rs index c1133e1cd..c0548ec09 100644 --- a/vendor/iana-time-zone/src/tz_linux.rs +++ b/vendor/iana-time-zone/src/tz_linux.rs @@ -1,7 +1,9 @@ use std::fs::{read_link, read_to_string}; pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> { - etc_localtime().or_else(|_| etc_timezone()) + etc_localtime() + .or_else(|_| etc_timezone()) + .or_else(|_| openwrt::etc_config_system()) } fn etc_timezone() -> Result<String, crate::GetTimezoneError> { @@ -43,3 +45,140 @@ fn etc_localtime() -> Result<String, crate::GetTimezoneError> { } Err(crate::GetTimezoneError::FailedParsingString) } + +mod openwrt { + use std::io::BufRead; + use std::{fs, io, iter}; + + pub(crate) fn etc_config_system() -> Result<String, crate::GetTimezoneError> { + let f = fs::OpenOptions::new() + .read(true) + .open("/etc/config/system")?; + let mut f = io::BufReader::new(f); + let mut in_system_section = false; + let mut line = String::with_capacity(80); + + // prefer option "zonename" (IANA time zone) over option "timezone" (POSIX time zone) + let mut timezone = None; + loop { + line.clear(); + f.read_line(&mut line)?; + if line.is_empty() { + break; + } + + let mut iter = IterWords(&line); + let mut next = || iter.next().transpose(); + + if let Some(keyword) = next()? { + if keyword == "config" { + in_system_section = next()? == Some("system") && next()?.is_none(); + } else if in_system_section && keyword == "option" { + if let Some(key) = next()? { + if key == "zonename" { + if let (Some(zonename), None) = (next()?, next()?) { + return Ok(zonename.to_owned()); + } + } else if key == "timezone" { + if let (Some(value), None) = (next()?, next()?) { + timezone = Some(value.to_owned()); + } + } + } + } + } + } + + timezone.ok_or_else(|| crate::GetTimezoneError::OsError) + } + + #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] + struct BrokenQuote; + + impl From<BrokenQuote> for crate::GetTimezoneError { + fn from(_: BrokenQuote) -> Self { + crate::GetTimezoneError::FailedParsingString + } + } + + /// Iterated over all words in a OpenWRT config line. + struct IterWords<'a>(&'a str); + + impl<'a> Iterator for IterWords<'a> { + type Item = Result<&'a str, BrokenQuote>; + + fn next(&mut self) -> Option<Self::Item> { + match read_word(self.0) { + Ok(Some((item, tail))) => { + self.0 = tail; + Some(Ok(item)) + } + Ok(None) => { + self.0 = ""; + None + } + Err(err) => { + self.0 = ""; + Some(Err(err)) + } + } + } + } + + impl iter::FusedIterator for IterWords<'_> {} + + /// Read the next word in a OpenWRT config line. Strip any surrounding quotation marks. + /// + /// Returns + /// + /// * a tuple `Some((word, remaining_line))` if found, + /// * `None` if the line is exhausted, or + /// * `Err(BrokenQuote)` if the line could not be parsed. + #[allow(clippy::manual_strip)] // needs to be compatile to 1.36 + fn read_word(s: &str) -> Result<Option<(&str, &str)>, BrokenQuote> { + let s = s.trim_start(); + if s.is_empty() || s.starts_with('#') { + Ok(None) + } else if s.starts_with('\'') { + let mut iter = s[1..].splitn(2, '\''); + match (iter.next(), iter.next()) { + (Some(item), Some(tail)) => Ok(Some((item, tail))), + _ => Err(BrokenQuote), + } + } else if s.starts_with('"') { + let mut iter = s[1..].splitn(2, '"'); + match (iter.next(), iter.next()) { + (Some(item), Some(tail)) => Ok(Some((item, tail))), + _ => Err(BrokenQuote), + } + } else { + let mut iter = s.splitn(2, |c: char| c.is_whitespace()); + match (iter.next(), iter.next()) { + (Some(item), Some(tail)) => Ok(Some((item, tail))), + _ => Ok(Some((s, ""))), + } + } + } + + #[cfg(test)] + #[test] + fn test_read_word() { + assert_eq!( + read_word(" option timezone 'CST-8'\n").unwrap(), + Some(("option", "timezone 'CST-8'\n")), + ); + assert_eq!( + read_word("timezone 'CST-8'\n").unwrap(), + Some(("timezone", "'CST-8'\n")), + ); + assert_eq!(read_word("'CST-8'\n").unwrap(), Some(("CST-8", "\n"))); + assert_eq!(read_word("\n").unwrap(), None); + + assert_eq!( + read_word(r#""time 'Zone'""#).unwrap(), + Some(("time 'Zone'", "")), + ); + + assert_eq!(read_word("'CST-8").unwrap_err(), BrokenQuote); + } +} |