flogging_macros/src/format.rs
Lines
100.00 %
Functions
100.00 %
Regions
100.00 %
| Line | Count | Source |
|---|---|---|
| 1 | // | |
| 2 | // File Name: fmt_log.rs | |
| 3 | // Project Name: flogging | |
| 4 | // | |
| 5 | // Copyright (C) 2025 Bradley Willcott | |
| 6 | // | |
| 7 | // SPDX-License-Identifier: GPL-3.0-or-later | |
| 8 | // | |
| 9 | // This library (crate) is free software: you can redistribute it and/or modify | |
| 10 | // it under the terms of the GNU General Public License as published by | |
| 11 | // the Free Software Foundation, either version 3 of the License, or | |
| 12 | // (at your option) any later version. | |
| 13 | // | |
| 14 | // This library (crate) is distributed in the hope that it will be useful, | |
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | // GNU General Public License for more details. | |
| 18 | // | |
| 19 | // You should have received a copy of the GNU General Public License | |
| 20 | // along with this library (crate). If not, see <https://www.gnu.org/licenses/>. | |
| 21 | // | |
| 22 | ||
| 23 | //! | |
| 24 | //! # format Macro Impl | |
| 25 | //! | |
| 26 | //! Format the Log function call (Rust code) | |
| 27 | //! | |
| 28 | ||
| 29 | use ::AsStrFormatExt; | |
| 30 | use ::TokenStream; | |
| 31 | use ::RegexBuilder; | |
| 32 | ||
| 33 | 33 | pub(crate) fn format_impl(fmt_str: &strmsg:) -> { |
| 34 | // println!("msg: {}", &msg); | |
| 35 | ||
| 36 | 32 | let= "let __fmt = format!({});\n"format(&[ |
| 37 | 33 | match process_msg(){ |
| 38 | 32 | Some() =>, |
| 39 | 1 | None => return ::(), |
| 40 | } | |
| 41 | ]); | |
| 42 | ||
| 43 | 32 | let mut= String::(); |
| 44 | 32 | push_str(&); |
| 45 | 32 | push_str(); |
| 46 | ||
| 47 | // let rtn = buf.parse().unwrap_or_default(); | |
| 48 | // println!("{rtn}"); | |
| 49 | // rtn | |
| 50 | 32 | parse()unwrap_or_default() |
| 51 | 33 | } |
| 52 | /// | |
| 53 | /// Check for `object` only `msg`. | |
| 54 | /// | |
| 55 | /// If found, provide default format string. | |
| 56 | /// | |
| 57 | 33 | fn process_msg(msg:) -> <> { |
| 58 | 33 | let=to_string(); |
| 59 | ||
| 60 | 33 | ifis_empty() { |
| 61 | 1 | return None; |
| 62 | 32 | } |
| 63 | ||
| 64 | 28 | ifstarts_with('\"') &&ends_with('\"') { |
| 65 | 19 | return Some(); |
| 66 | 13 | } |
| 67 | ||
| 68 | 13 | let= "(?<fmt>\".*\\{.*\\}.*\")(,[\\s]*(?<attrs>.*)*)"; |
| 69 | ||
| 70 | 13 | let= ::() |
| 71 | 13 | dot_matches_new_line(true) |
| 72 | 13 | build() |
| 73 | 13 | unwrap(); |
| 74 | ||
| 75 | 13 | ifis_match(&) { |
| 76 | 9 | Some() |
| 77 | } else { | |
| 78 | 4 | let=split(',')count(); |
| 79 | ||
| 80 | 4 | let mut= String::(); |
| 81 | ||
| 82 | 3 | if== 1 { |
| 83 | 3 | push_str("\"{}\", "); |
| 84 | 3 | } else { |
| 85 | 1 | push_str("\"{}"); |
| 86 | ||
| 87 | 2 | forin 1..{ |
| 88 | 2 | push_str(", {}"); |
| 89 | 2 | } |
| 90 | ||
| 91 | 1 | push_str("\", "); |
| 92 | } | |
| 93 | ||
| 94 | 4 | push_str(&); |
| 95 | ||
| 96 | 4 | Some() |
| 97 | } | |
| 98 | 33 | } |