diff options
-rw-r--r-- | Cargo.lock | 391 | ||||
-rw-r--r-- | Cargo.toml | 14 | ||||
-rw-r--r-- | src/main.rs | 54 | ||||
-rw-r--r-- | src/qif.rs | 131 |
4 files changed, 376 insertions, 214 deletions
@@ -1,261 +1,376 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" -version = "0.6.3" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ - "memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] -name = "ansi_term" -version = "0.10.2" +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bitflags" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" + +[[package]] +name = "cc" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] -name = "atty" -version = "0.2.6" +name = "clap" +version = "4.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42dfd32784433290c51d92c438bb72ea5063797fc3cc9a21a8c4346bebbb2098" dependencies = [ - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 2.0.2", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", ] [[package]] -name = "bitflags" -version = "1.0.1" +name = "clap_derive" +version = "4.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fddf67631444a3a3e3e5ac51c36a5e01335302de677bd78759eaa90ab1f46644" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "clap" -version = "2.29.0" +name = "clap_lex" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" dependencies = [ - "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "os_str_bytes", ] [[package]] -name = "lazy_static" -version = "0.2.11" +name = "errno" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] [[package]] -name = "lazy_static" -version = "1.0.0" +name = "errno-dragonfly" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] [[package]] -name = "libc" -version = "0.2.33" +name = "heck" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "memchr" -version = "1.0.2" +name = "hermit-abi" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + +[[package]] +name = "io-lifetimes" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd6da19f25979c7270e70fa95ab371ec3b701cd0eefc47667a09785b3c59155" dependencies = [ - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", + "windows-sys", ] [[package]] -name = "qif_parser" -version = "0.1.0" +name = "is-terminal" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" dependencies = [ - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt-derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", ] [[package]] -name = "quote" -version = "0.3.15" +name = "lazy_static" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "redox_syscall" -version = "0.1.33" +name = "libc" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] -name = "redox_termios" -version = "0.1.1" +name = "linux-raw-sys" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "os_str_bytes" +version = "6.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", ] [[package]] -name = "regex" -version = "0.2.2" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "version_check", ] [[package]] -name = "regex-syntax" -version = "0.4.1" +name = "proc-macro2" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +dependencies = [ + "unicode-ident", +] [[package]] -name = "strsim" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +name = "qif_parser" +version = "0.1.0" +dependencies = [ + "clap", + "lazy_static", + "regex", +] [[package]] -name = "structopt" -version = "0.1.6" +name = "quote" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ - "clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] -name = "structopt-derive" -version = "0.1.6" +name = "regex" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", ] [[package]] -name = "syn" -version = "0.11.11" +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustix" +version = "0.36.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fe885c3a125aa45213b68cc1472a49880cb5923dc23f522ad2791b882228778" dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", ] [[package]] -name = "synom" -version = "0.11.3" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "termion" -version = "1.5.1" +name = "termcolor" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util", ] [[package]] -name = "textwrap" -version = "0.9.0" +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "winapi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] -name = "thread_local" -version = "0.3.4" +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 = [ - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] -name = "unicode-width" -version = "0.1.4" +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 = "unicode-xid" -version = "0.0.4" +name = "windows-sys" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] [[package]] -name = "unreachable" -version = "1.0.0" +name = "windows-targets" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] -name = "utf8-ranges" -version = "1.0.0" +name = "windows_aarch64_gnullvm" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] -name = "vec_map" -version = "0.8.0" +name = "windows_aarch64_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] -name = "void" -version = "1.0.2" +name = "windows_i686_gnu" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] -name = "winapi" -version = "0.3.2" +name = "windows_i686_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.3.2" +name = "windows_x86_64_gnu" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" -"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455" -"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859" -"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" -"checksum clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "110d43e343eb29f4f51c1db31beb879d546db27998577e5715270a54bcf41d3f" -"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" -"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" -"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2" -"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" -"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "07b8f011e3254d5a9b318fde596d409a0001c9ae4c6e7907520c2eaa4d988c99" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" -"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" -"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" -"checksum structopt 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "daed460ef88cdfdc6cc665f974feea29883c40f479b6976302c8ad8bf05de722" -"checksum structopt-derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4da119c9a7a1eccb7c6de0c1eb3f7ed1c11138624d092b3687222aeed8f1375c" -"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693" -"checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" -"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" -"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" -"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" -"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum winapi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "890b38836c01d72fdb636d15c9cfc52ec7fd783b330abc93cd1686f4308dfccc" -"checksum winapi-i686-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ec6667f60c23eca65c561e63a13d81b44234c2e38a6b6c959025ee907ec614cc" -"checksum winapi-x86_64-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98f12c52b2630cd05d2c3ffd8e008f7f48252c042b4871c72aed9dc733b96668" +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" @@ -2,9 +2,15 @@ name = "qif_parser" version = "0.1.0" authors = ["Justin Worthe <justin@worthe-it.co.za>"] +edition = "2018" [dependencies] -regex = "0.2.2" -lazy_static = "1.0" -structopt = "0.1.6" -structopt-derive = "0.1.6"
\ No newline at end of file +regex = "1.7" +lazy_static = "1" +clap = { version = "4.1", features = ["derive"] } + +[profile.dev.package."*"] +opt-level = 3 +# incremental compile is rarely useful for dependencies since they change +# infrequently, and having this on breaks sccache +incremental = false diff --git a/src/main.rs b/src/main.rs index 8874ea9..37644c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,42 +1,30 @@ -extern crate regex; -#[macro_use] extern crate lazy_static; -extern crate structopt; -#[macro_use] extern crate structopt_derive; - pub mod qif; -use structopt::StructOpt; - +use clap::Parser; use qif::*; -use std::io::prelude::*; -use std::io::*; - -use std::ffi::{OsString, OsStr}; -use std::path::PathBuf; -use std::result::Result; - -use std::fs::File; -use std::error::Error; - -fn parse_filepath(str: &OsStr) -> Result<PathBuf, OsString> { - let path: PathBuf = ::std::convert::From::from(str); - if path.is_file() { - Ok(path) - } else { - Err(str.to_os_string()) - } -} - -#[derive(StructOpt, Debug)] -#[structopt(name = "Qif Parser", about = "Qif file preprocessor to decrease duplication when importing to gnucash")] +use std::{ + error::Error, + fs::File, + io::{prelude::*, *}, + path::PathBuf, + result::Result, +}; + +/// Qif file preprocessor to decrease duplication when importing to gnucash +#[derive(Parser, Debug)] +#[structopt( + name = "Qif Parser", + version, about, long_about = None +)] struct CliArgs { - #[structopt(help = "Files to preprocess", required, parse(try_from_os_str="parse_filepath"))] - files: Vec<PathBuf> + /// Files to preprocess + #[arg(value_hint = clap::ValueHint::FilePath)] + files: Vec<PathBuf>, } -fn main() -> Result<(), Box<Error>> { - let args = CliArgs::from_args(); - +fn main() -> Result<(), Box<dyn Error>> { + let args = CliArgs::parse(); + for filepath in &args.files { let file = File::open(filepath)?; let file_reader = BufReader::new(file); @@ -1,18 +1,19 @@ -use std::fmt; +use lazy_static::lazy_static; use regex::Regex; -use std::result::Result; use std::error::Error; +use std::fmt; +use std::result::Result; pub struct QifFile { header: String, - entries: Vec<QifEntry> + entries: Vec<QifEntry>, } impl QifFile { pub fn new(header: String) -> QifFile { QifFile { - header: header, - entries: Vec::new() + header, + entries: Vec::new(), } } @@ -40,7 +41,7 @@ impl fmt::Display for QifFile { pub struct QifEntry { date: String, amount: String, - description: String + description: String, } const DATE_PREFIX: &str = "D"; @@ -56,7 +57,7 @@ impl QifEntry { (Some(date), Some(amount), Some(description)) => Ok(QifEntry { date: date.chars().skip(1).collect(), amount: amount.chars().skip(1).collect(), - description: description.chars().skip(1).collect() + description: description.chars().skip(1).collect(), }), (None, _, _) => Err(QifParsingError::MissingDate), (_, None, _) => Err(QifParsingError::MissingAmount), @@ -65,65 +66,117 @@ impl QifEntry { } pub fn is_empty(&self) -> bool { - self.amount == String::from("0") + &self.amount == "0" || &self.amount == "0.00" } pub fn clean_description(&self) -> String { - let replaced_date = replace_date(&self.description); - replace_common(&replaced_date) + let mut new_description = self.description.clone(); + for algorithm in [ + remove_date, + remove_card_number, + replace_common, + remove_payment_provider, + ] { + new_description = algorithm(&new_description); + } + new_description } } impl fmt::Display for QifEntry { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}{}\n{}{}\n{}{}", - DATE_PREFIX, self.date, - AMOUNT_PREFIX, self.amount, - DESCRIPTION_PREFIX, self.clean_description() + write!( + f, + "{}{}\n{}{}\n{}{}", + DATE_PREFIX, + self.date, + AMOUNT_PREFIX, + self.amount, + DESCRIPTION_PREFIX, + self.clean_description() ) } } -fn replace_date(text: &str) -> String { +fn remove_date(text: &str) -> String { lazy_static! { - static ref DATE_REGEX: Regex = Regex::new(r"(?i)(\d{2} )?(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)( \d{4})?").unwrap(); + static ref DATE_REGEX: Regex = + Regex::new(r"(?i)\d{2} (JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)( \d{4})?") + .unwrap(); } DATE_REGEX.replace_all(text, "").trim().to_string() } +fn remove_card_number(text: &str) -> String { + lazy_static! { + static ref CARD_NUM_REGEX: Regex = Regex::new(r"(\d{6}\*+\d{4}|\d{16})").unwrap(); + } + CARD_NUM_REGEX.replace_all(text, "").trim().to_string() +} + +fn remove_payment_provider(text: &str) -> String { + lazy_static! { + static ref PURCH_REGEX: Regex = + Regex::new(r"(?i)^(purch( payfast\*)?|pp +\*|c\*|yoco +\*|ikh\*)").unwrap(); + } + PURCH_REGEX.replace_all(text, "").trim().to_string() +} + fn replace_common(text: &str) -> String { lazy_static! { static ref COMMON_NAMES: Vec<(Regex, &'static str)> = vec!( - (Regex::new(r"(?i)(pick n pay|pnp)").unwrap(), "Pick n Pay"), - (Regex::new(r"(?i)checkers").unwrap(), "Checkers"), - (Regex::new(r"(?i)WOOLWORTHS").unwrap(), "Woolworths"), - (Regex::new(r"(?i)clicks").unwrap(), "Clicks"), - (Regex::new(r"(?i)spar").unwrap(), "Spar"), - (Regex::new(r"(?i)Crazy store").unwrap(), "Crazy Store"), - (Regex::new(r"^PNA").unwrap(), "PNA"), - (Regex::new(r"(?i)sahl").unwrap(), "SA Home Loans"), - (Regex::new(r"(?i)gautrain").unwrap(), "Gautrain"), - (Regex::new(r"(?i)BANK YOUR CHANGE DEBI").unwrap(), "TO SAVINGS POCKET"), - (Regex::new(r"(?i)AFRIHOST").unwrap(), "Afrihost"), - (Regex::new(r"(?i)DIALDIRECT").unwrap(), "Dialdirect"), - (Regex::new(r"(?i)STEERS").unwrap(), "Steers"), - (Regex::new(r"(?i)CELL C").unwrap(), "Cell C"), - (Regex::new(r"(?i)ELECTRICITY").unwrap(), "Electricity"), - (Regex::new(r"(?i)(COUNTRY VIEW|STAR STOP|Shell|Sasol)").unwrap(), "Petrol"), - (Regex::new(r"(?i)kung ?-?fu").unwrap(), "Kungfu Kitchen"), - ); + (r"(?i)(pick n pay|pnp)", "Pick n Pay"), + (r"(?i)checkers", "Checkers"), + (r"(?i)WOOLWORTHS", "Woolworths"), + (r"(?i)clicks", "Clicks"), + (r"(?i)dischem", "Dischem"), + (r"(?i)spar", "Spar"), + (r"(?i)(disc memb|disc prem)", "Discovery medical aid"), + (r"(?i)10XRA", "10X Retirement Annuity"), + (r"(?i)NEDABF/MFC", "Nedbank MFC"), + (r"(?i)SARSEFLNG", "SARS Efiling"), + (r"(?i)Crazy store", "Crazy Store"), + (r"^PNA", "PNA"), + (r"^BWH", "Builders Warehouse"), + (r"^MCD ", "McDonalds"), + (r"^MRP ", "Mr Price"), + (r"NakedIn", "Naked Insurance"), + (r"(?i)sahl", "SA Home Loans"), + (r"(?i)gautrain", "Gautrain"), + (r"(?i)BYC DEBIT", "TO SAVINGS POCKET"), + (r"(?i)AFRIHOST", "Afrihost"), + (r"(?i)DIALDIRECT", "Dialdirect"), + (r"(?i)STEERS", "Steers"), + (r"(?i)CELL C", "Cell C"), + (r"(?i)ELECTRICITY", "Electricity"), + (r"(?i)(COUNTRY VIEW|STAR STOP|Shell|Sasol|Engen)", "Petrol"), + (r"(?i)kung ?-?fu", "Kungfu Kitchen"), + (r"(?i)^atm cash", "Cash"), + (r"(?i)DRS CL & ME LA", "Medipark 24") + ) + .into_iter() + .map(|(from, to)| (Regex::new(from).unwrap(), to)) + .collect(); } - COMMON_NAMES.iter().fold( - text, |acc, next| if next.0.is_match(acc) {next.1} else {acc} - ).to_string() + COMMON_NAMES + .iter() + .filter_map(|(rule, replacement)| { + if rule.is_match(text) { + Some(replacement.to_string()) + } else { + None + } + }) + .next() + .unwrap_or_else(|| text.to_owned()) + .to_string() } - #[derive(Debug)] pub enum QifParsingError { MissingDate, MissingAmount, - MissingDescription + MissingDescription, } impl fmt::Display for QifParsingError { |