From 135f4861ffc413865b4bee6b721ccf0917958130 Mon Sep 17 00:00:00 2001 From: Joel Wachsler Date: Tue, 19 Jul 2022 22:24:02 +0000 Subject: [PATCH] Remove util --- .../src/parser/group/method/mod.rs | 11 ++++++++--- .../src/parser/group/method/return_type.rs | 9 ++------- .../src/parser/group/method/url.rs | 4 ++-- qbittorrent-web-api-gen/src/parser/group/url.rs | 14 ++++++++++++-- qbittorrent-web-api-gen/src/parser/mod.rs | 1 - qbittorrent-web-api-gen/src/parser/util.rs | 15 --------------- 6 files changed, 24 insertions(+), 30 deletions(-) delete mode 100644 qbittorrent-web-api-gen/src/parser/util.rs diff --git a/qbittorrent-web-api-gen/src/parser/group/method/mod.rs b/qbittorrent-web-api-gen/src/parser/group/method/mod.rs index e3de6cf..1099227 100644 --- a/qbittorrent-web-api-gen/src/parser/group/method/mod.rs +++ b/qbittorrent-web-api-gen/src/parser/group/method/mod.rs @@ -2,7 +2,7 @@ mod description; mod return_type; mod url; -use crate::{md_parser, parser::util, types}; +use crate::{md_parser, types}; pub use return_type::ReturnType; use std::collections::HashMap; @@ -74,8 +74,13 @@ impl ApiMethod { } impl md_parser::TokenTree { - fn find_content_starts_with(&self, content: &str) -> Option { - util::find_content_starts_with(&self.content, content) + fn find_content_starts_with(&self, starts_with: &str) -> Option { + self.content.iter().find_map(|row| match row { + md_parser::MdContent::Text(content) if content.starts_with(starts_with) => { + Some(content.into()) + } + _ => None, + }) } } diff --git a/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs b/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs index 72fa7fc..6b8fc5b 100644 --- a/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs +++ b/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::{ - md_parser::{self, MdContent}, + md_parser, parser::{types, ReturnTypeParameter}, }; @@ -47,12 +47,7 @@ impl md_parser::TokenTree { } fn is_list(&self) -> bool { - self.content - .iter() - .find_map(|row| match row { - MdContent::Text(text) if text.starts_with("The response is a") => Some(text), - _ => None, - }) + self.find_content_starts_with("The response is a") .map(|found| found.contains("array")) .unwrap_or_else(|| false) } diff --git a/qbittorrent-web-api-gen/src/parser/group/method/url.rs b/qbittorrent-web-api-gen/src/parser/group/method/url.rs index 1911961..ff35a32 100644 --- a/qbittorrent-web-api-gen/src/parser/group/method/url.rs +++ b/qbittorrent-web-api-gen/src/parser/group/method/url.rs @@ -1,10 +1,10 @@ -use crate::{md_parser, parser::util}; +use crate::md_parser; impl md_parser::TokenTree { pub fn get_method_url(&self) -> String { const START: &str = "Name: "; - util::find_content_starts_with(&self.content, START) + self.find_content_starts_with(START) .map(|text| text.trim_start_matches(START).trim_matches('`').to_string()) .expect("Could find method url") } diff --git a/qbittorrent-web-api-gen/src/parser/group/url.rs b/qbittorrent-web-api-gen/src/parser/group/url.rs index b806b8c..4f67c6f 100644 --- a/qbittorrent-web-api-gen/src/parser/group/url.rs +++ b/qbittorrent-web-api-gen/src/parser/group/url.rs @@ -1,10 +1,11 @@ use regex::Regex; -use crate::{md_parser, parser::util}; +use crate::md_parser; impl md_parser::TokenTree { pub fn get_group_url(&self) -> String { - let row = util::find_content_contains(&self.content, "API methods are under") + let row = self + .find_content_contains("API methods are under") .expect("Could not find api method"); let re = Regex::new(r#"All (?:\w+\s?)+ API methods are under "(\w+)", e.g."#) @@ -13,4 +14,13 @@ impl md_parser::TokenTree { let res = re.captures(&row).expect("Failed find capture"); res[1].to_string() } + + fn find_content_contains(&self, contains: &str) -> Option { + self.content.iter().find_map(|row| match row { + md_parser::MdContent::Text(content) if content.contains(contains) => { + Some(content.into()) + } + _ => None, + }) + } } diff --git a/qbittorrent-web-api-gen/src/parser/mod.rs b/qbittorrent-web-api-gen/src/parser/mod.rs index ec3b78a..e5d8968 100644 --- a/qbittorrent-web-api-gen/src/parser/mod.rs +++ b/qbittorrent-web-api-gen/src/parser/mod.rs @@ -1,7 +1,6 @@ use crate::{md_parser, types}; mod group; -mod util; #[derive(Debug)] pub struct ReturnTypeParameter { diff --git a/qbittorrent-web-api-gen/src/parser/util.rs b/qbittorrent-web-api-gen/src/parser/util.rs deleted file mode 100644 index 71e9160..0000000 --- a/qbittorrent-web-api-gen/src/parser/util.rs +++ /dev/null @@ -1,15 +0,0 @@ -use crate::md_parser::MdContent; - -pub fn find_content_starts_with(content: &[MdContent], starts_with: &str) -> Option { - content.iter().find_map(|row| match row { - MdContent::Text(content) if content.starts_with(starts_with) => Some(content.into()), - _ => None, - }) -} - -pub fn find_content_contains(content: &[MdContent], contains: &str) -> Option { - content.iter().find_map(|row| match row { - MdContent::Text(content) if content.contains(contains) => Some(content.into()), - _ => None, - }) -}