Remove util

This commit is contained in:
Joel Wachsler 2022-07-19 22:24:02 +00:00
parent af49a83034
commit 135f4861ff
6 changed files with 24 additions and 30 deletions

View File

@ -2,7 +2,7 @@ mod description;
mod return_type; mod return_type;
mod url; mod url;
use crate::{md_parser, parser::util, types}; use crate::{md_parser, types};
pub use return_type::ReturnType; pub use return_type::ReturnType;
use std::collections::HashMap; use std::collections::HashMap;
@ -74,8 +74,13 @@ impl ApiMethod {
} }
impl md_parser::TokenTree { impl md_parser::TokenTree {
fn find_content_starts_with(&self, content: &str) -> Option<String> { fn find_content_starts_with(&self, starts_with: &str) -> Option<String> {
util::find_content_starts_with(&self.content, content) self.content.iter().find_map(|row| match row {
md_parser::MdContent::Text(content) if content.starts_with(starts_with) => {
Some(content.into())
}
_ => None,
})
} }
} }

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::{ use crate::{
md_parser::{self, MdContent}, md_parser,
parser::{types, ReturnTypeParameter}, parser::{types, ReturnTypeParameter},
}; };
@ -47,12 +47,7 @@ impl md_parser::TokenTree {
} }
fn is_list(&self) -> bool { fn is_list(&self) -> bool {
self.content self.find_content_starts_with("The response is a")
.iter()
.find_map(|row| match row {
MdContent::Text(text) if text.starts_with("The response is a") => Some(text),
_ => None,
})
.map(|found| found.contains("array")) .map(|found| found.contains("array"))
.unwrap_or_else(|| false) .unwrap_or_else(|| false)
} }

View File

@ -1,10 +1,10 @@
use crate::{md_parser, parser::util}; use crate::md_parser;
impl md_parser::TokenTree { impl md_parser::TokenTree {
pub fn get_method_url(&self) -> String { pub fn get_method_url(&self) -> String {
const START: &str = "Name: "; 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()) .map(|text| text.trim_start_matches(START).trim_matches('`').to_string())
.expect("Could find method url") .expect("Could find method url")
} }

View File

@ -1,10 +1,11 @@
use regex::Regex; use regex::Regex;
use crate::{md_parser, parser::util}; use crate::md_parser;
impl md_parser::TokenTree { impl md_parser::TokenTree {
pub fn get_group_url(&self) -> String { 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"); .expect("Could not find api method");
let re = Regex::new(r#"All (?:\w+\s?)+ API methods are under "(\w+)", e.g."#) 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"); let res = re.captures(&row).expect("Failed find capture");
res[1].to_string() res[1].to_string()
} }
fn find_content_contains(&self, contains: &str) -> Option<String> {
self.content.iter().find_map(|row| match row {
md_parser::MdContent::Text(content) if content.contains(contains) => {
Some(content.into())
}
_ => None,
})
}
} }

View File

@ -1,7 +1,6 @@
use crate::{md_parser, types}; use crate::{md_parser, types};
mod group; mod group;
mod util;
#[derive(Debug)] #[derive(Debug)]
pub struct ReturnTypeParameter { pub struct ReturnTypeParameter {

View File

@ -1,15 +0,0 @@
use crate::md_parser::MdContent;
pub fn find_content_starts_with(content: &[MdContent], starts_with: &str) -> Option<String> {
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<String> {
content.iter().find_map(|row| match row {
MdContent::Text(content) if content.contains(contains) => Some(content.into()),
_ => None,
})
}