1616namespace KindleMate2 {
1717 public partial class FrmMain : Form {
1818 [ DllImport ( "User32.dll" ) ]
19- static extern bool HideCaret ( IntPtr hWnd ) ;
19+ private static extern bool HideCaret ( IntPtr hWnd ) ;
2020
2121 [ DllImport ( "user32.dll" ) ]
22- static extern bool DestroyCaret ( ) ;
22+ private static extern bool DestroyCaret ( ) ;
2323
2424 private DataTable _clippingsDataTable = new ( ) ;
2525
@@ -848,7 +848,7 @@ .. File.ReadAllLines(clippingsPath)
848848 }
849849 var line5 = lines [ florDelimiter ] . Trim ( ) ; // line 5 is "=========="
850850
851- var result = HandleClipplings ( line1 , line2 , line3 , line4 , line5 ) ;
851+ var result = HandleClippings ( line1 , line2 , line3 , line4 , line5 ) ;
852852 if ( result ) {
853853 insertedCount ++ ;
854854 }
@@ -863,7 +863,7 @@ .. File.ReadAllLines(clippingsPath)
863863 return Strings . Parsed_X + Strings . Space + delimiterIndex . Count + Strings . Space + Strings . X_Clippings + Strings . Symbol_Comma + Strings . Imported_X + Strings . Space + insertedCount + Strings . Space + Strings . X_Clippings ;
864864 }
865865
866- private bool HandleClipplings ( string line1 , string line2 , string line3 , string line4 , string line5 , bool isRebuild = false ) {
866+ private bool HandleClippings ( string line1 , string line2 , string line3 , string line4 , string line5 , bool isRebuild = false ) {
867867 var entityClipping = new Clipping ( ) ;
868868
869869 var content = line4 ;
@@ -924,8 +924,7 @@ private bool HandleClipplings(string line1, string line2, string line3, string l
924924 var datetime = split_b [ ^ 1 ] . Replace ( "Added on" , "" ) . Replace ( "添加于" , "" ) . Trim ( ) ;
925925 datetime = datetime [ ( datetime . IndexOf ( ',' ) + 1 ) ..] . Trim ( ) ;
926926 // ReSharper disable once InlineOutVariableDeclaration
927- DateTime parsedDate ;
928- var isDateParsed = DateTime . TryParseExact ( datetime , "MMMM d, yyyy h:m:s tt" , CultureInfo . GetCultureInfo ( "en-US" ) , DateTimeStyles . None , out parsedDate ) ;
927+ var isDateParsed = DateTime . TryParseExact ( datetime , "MMMM d, yyyy h:m:s tt" , CultureInfo . GetCultureInfo ( "en-US" ) , DateTimeStyles . None , out DateTime parsedDate ) ;
929928 if ( ! isDateParsed ) {
930929 var dayOfWeekIndex = datetime . IndexOf ( "星期" , StringComparison . Ordinal ) ;
931930 if ( dayOfWeekIndex != - 1 ) {
@@ -955,8 +954,7 @@ private bool HandleClipplings(string line1, string line2, string line3, string l
955954
956955 string bookname ;
957956 string authorname ;
958- const string pattern = @"\(([^()]+)\)[^(]*$" ;
959- Match match = Regex . Match ( line1 , pattern ) ;
957+ Match match = BookNameRegex ( ) . Match ( line1 ) ;
960958 if ( match . Success ) {
961959 authorname = match . Groups [ 1 ] . Value . Trim ( ) ;
962960 bookname = line1 . Replace ( match . Groups [ 0 ] . Value . Trim ( ) , "" ) . Trim ( ) ;
@@ -2110,7 +2108,7 @@ private string RebuildDatabase() {
21102108 return Strings . No_Data_To_Clear ;
21112109 }
21122110 _ = _staticData . EmptyTable ( "clippings" ) ;
2113- var insertedCount = ( from DataRow row in origin . Rows let entityClipping = new Clipping ( ) let line1 = row [ "line1" ] . ToString ( ) ?? string . Empty let line2 = row [ "line2" ] . ToString ( ) ?? string . Empty let line3 = row [ "line3" ] . ToString ( ) ?? string . Empty let line4 = row [ "line4" ] . ToString ( ) ?? string . Empty let line5 = row [ "line5" ] . ToString ( ) ?? string . Empty select HandleClipplings ( line1 , line2 , line3 , line4 , line5 , true ) ) . Count ( result => result ) ;
2111+ var insertedCount = ( from DataRow row in origin . Rows let entityClipping = new Clipping ( ) let line1 = row [ "line1" ] . ToString ( ) ?? string . Empty let line2 = row [ "line2" ] . ToString ( ) ?? string . Empty let line3 = row [ "line3" ] . ToString ( ) ?? string . Empty let line4 = row [ "line4" ] . ToString ( ) ?? string . Empty let line5 = row [ "line5" ] . ToString ( ) ?? string . Empty select HandleClippings ( line1 , line2 , line3 , line4 , line5 , true ) ) . Count ( result => result ) ;
21142112 _staticData . CommitTransaction ( ) ;
21152113 var clipping = Strings . Parsed_X + Strings . Space + origin . Rows . Count + Strings . Space + Strings . X_Clippings + Strings . Symbol_Comma + Strings . Imported_X + Strings . Space + insertedCount + Strings . Space + Strings . X_Clippings ;
21162114 return clipping ;
@@ -2166,18 +2164,24 @@ private string CleanDatabase() {
21662164 continue ;
21672165 }
21682166
2169- if ( ! contentTrimmed . Equals ( content ) && ! booknameTrimmed . Equals ( bookname ) ) {
2170- if ( _staticData . UpdateClippings ( key , contentTrimmed , booknameTrimmed ) ) {
2171- countTrimmed ++ ;
2172- }
2173- } else if ( ! contentTrimmed . Equals ( content ) ) {
2174- if ( _staticData . UpdateClippings ( key , contentTrimmed , bookname ) ) {
2175- countTrimmed ++ ;
2176- }
2177- } else if ( ! booknameTrimmed . Equals ( bookname ) ) {
2178- if ( _staticData . UpdateClippings ( key , string . Empty , booknameTrimmed ) ) {
2179- countTrimmed ++ ;
2180- }
2167+ switch ( contentTrimmed . Equals ( content ) ) {
2168+ case false when ! booknameTrimmed . Equals ( bookname ) :
2169+ if ( _staticData . UpdateClippings ( key , contentTrimmed , booknameTrimmed ) ) {
2170+ countTrimmed ++ ;
2171+ }
2172+ break ;
2173+ case false :
2174+ if ( _staticData . UpdateClippings ( key , contentTrimmed , bookname ) ) {
2175+ countTrimmed ++ ;
2176+ }
2177+ break ;
2178+ default :
2179+ if ( ! booknameTrimmed . Equals ( bookname ) ) {
2180+ if ( _staticData . UpdateClippings ( key , string . Empty , booknameTrimmed ) ) {
2181+ countTrimmed ++ ;
2182+ }
2183+ }
2184+ break ;
21812185 }
21822186
21832187 if ( _staticData . IsExistClippingsOfContent ( content ) > 1 ) {
@@ -2551,7 +2555,7 @@ private void CmbSearch_SelectedIndexChanged(object sender, EventArgs e) {
25512555 list . AddRange ( _staticData . GetVocabStemList ( ) ) ;
25522556 }
25532557 var autoCompleteStringCollection = new AutoCompleteStringCollection ( ) ;
2554- autoCompleteStringCollection . AddRange ( list . ToArray ( ) ) ;
2558+ autoCompleteStringCollection . AddRange ( [ .. list ] ) ;
25552559 txtSearch . AutoCompleteSource = AutoCompleteSource . CustomSource ;
25562560 txtSearch . AutoCompleteCustomSource = autoCompleteStringCollection ;
25572561 }
@@ -2620,5 +2624,8 @@ private static string RemoveControlChar(string input) {
26202624 }
26212625 return output . ToString ( ) ;
26222626 }
2627+
2628+ [ GeneratedRegex ( @"\(([^()]+)\)[^(]*$" ) ]
2629+ private static partial Regex BookNameRegex ( ) ;
26232630 }
26242631}
0 commit comments