File tree Expand file tree Collapse file tree 4 files changed +42
-50
lines changed
Expand file tree Collapse file tree 4 files changed +42
-50
lines changed Original file line number Diff line number Diff line change 1+ ## v0.2.23
2+
3+ + support color display
4+
15## v0.2.22
26+ Fixed the cache can't update with new added problems
37
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ path = "src/bin/lc.rs"
44
55[package ]
66name = " leetcode-cli"
7- version = " 0.2.22 "
7+ version = " 0.2.23 "
88authors = [" clearloop <cdr.today@foxmail.com>" ]
99edition = " 2018"
1010description = " Leet your code in command-line."
Original file line number Diff line number Diff line change @@ -112,58 +112,40 @@ mod html {
112112 }
113113
114114 pub fn superscript ( n : u8 ) -> String {
115- if n == 0 {
116- "⁰" . to_owned ( )
117- } else if n == 1 {
118- "¹" . to_owned ( )
119- } else if n == 2 {
120- "²" . to_owned ( )
121- } else if n == 3 {
122- "³" . to_owned ( )
123- } else if n == 4 {
124- "⁴" . to_owned ( )
125- } else if n == 5 {
126- "⁵" . to_owned ( )
127- } else if n == 6 {
128- "⁶" . to_owned ( )
129- } else if n == 7 {
130- "⁷" . to_owned ( )
131- } else if n == 8 {
132- "⁸" . to_owned ( )
133- } else if n == 9 {
134- "⁹" . to_owned ( )
135- } else if n >= 10 {
136- superscript ( n / 10 ) + & superscript ( n % 10 )
137- } else {
138- n. to_string ( )
115+ match n {
116+ 0 => "⁰" . to_string ( ) ,
117+ 1 => "¹" . to_string ( ) ,
118+ 2 => "²" . to_string ( ) ,
119+ 3 => "³" . to_string ( ) ,
120+ 4 => "⁴" . to_string ( ) ,
121+ 5 => "⁵" . to_string ( ) ,
122+ 6 => "⁶" . to_string ( ) ,
123+ 7 => "⁷" . to_string ( ) ,
124+ 8 => "⁸" . to_string ( ) ,
125+ 9 => "⁹" . to_string ( ) ,
126+ x if x > 10 => ( superscript ( n / 10 ) . parse ( ) . unwrap_or ( 0 )
127+ + & superscript ( n % 10 ) . parse ( ) . unwrap_or ( 0 ) )
128+ . to_string ( ) ,
129+ _ => n. to_string ( ) ,
139130 }
140131 }
141132
142133 pub fn subscript ( n : u8 ) -> String {
143- if n >= 10 {
144- subscript ( n / 10 ) + & subscript ( n % 10 )
145- } else if n == 0 {
146- "₀" . to_owned ( )
147- } else if n == 1 {
148- "₁" . to_owned ( )
149- } else if n == 2 {
150- "₂" . to_owned ( )
151- } else if n == 3 {
152- "₃" . to_owned ( )
153- } else if n == 4 {
154- "₄" . to_owned ( )
155- } else if n == 5 {
156- "₅" . to_owned ( )
157- } else if n == 6 {
158- "₆" . to_owned ( )
159- } else if n == 7 {
160- "₇" . to_owned ( )
161- } else if n == 8 {
162- "₈" . to_owned ( )
163- } else if n == 9 {
164- "₉" . to_owned ( )
165- } else {
166- n. to_string ( )
134+ match n {
135+ x if x >= 10 => ( subscript ( n / 10 ) . parse ( ) . unwrap_or ( 0 )
136+ + & subscript ( n % 10 ) . parse ( ) . unwrap_or ( 0 ) )
137+ . to_string ( ) ,
138+ 0 => "₀" . to_string ( ) ,
139+ 1 => "₁" . to_string ( ) ,
140+ 2 => "₂" . to_string ( ) ,
141+ 3 => "₃" . to_string ( ) ,
142+ 4 => "₄" . to_string ( ) ,
143+ 5 => "₅" . to_string ( ) ,
144+ 6 => "₆" . to_string ( ) ,
145+ 7 => "₇" . to_string ( ) ,
146+ 8 => "₈" . to_string ( ) ,
147+ 9 => "₉" . to_string ( ) ,
148+ _ => n. to_string ( ) ,
167149 }
168150 }
169151 impl HTML for String {
@@ -179,6 +161,12 @@ mod html {
179161 let mut sup = false ;
180162 let mut sub = false ;
181163 let mut color: Option < Color > = None ;
164+
165+ // TODO: check how to make this `unwrap` more flexible..
166+ //
167+ // or looks better.
168+ //
169+ // or do some handwrite matching.
182170 let re_color = Regex :: new ( r#"color=['"]([^'"]+)"# ) . unwrap ( ) ;
183171 for ( i, e) in tks. chars ( ) . enumerate ( ) {
184172 match e {
Original file line number Diff line number Diff line change 2828//! **Please make sure you have logined in `leetcode.com` with `chrome`**, more info plz checkout [this](#cookies)
2929//!
3030//! ```sh
31- //! leetcode 0.2.22
31+ //! leetcode 0.2.23
3232//! May the Code be with You 👻
3333//!
3434//! USAGE:
You can’t perform that action at this time.
0 commit comments