22// System : Sandcastle Help File Builder Utilities
33// File : TitleAndKeywordHtmlExtract.cs
44// Author : Eric Woodruff ([email protected] ) 5- // Updated : 03/31/2022
6- // Note : Copyright 2008-2022 , Eric Woodruff, All rights reserved
5+ // Updated : 12/14/2024
6+ // Note : Copyright 2008-2024 , Eric Woodruff, All rights reserved
77//
88// This file contains the class used to extract title and keyword information from HTML files for use in creating
99// the Help 1 (CHM) table of contents and keyword index files. It can also optionally convert the
@@ -108,6 +108,9 @@ private struct KeywordInfo
108108 //=====================================================================
109109
110110 private readonly BuildProcess currentBuild ;
111+ private readonly object lockObject = new Object ( ) ;
112+ private static readonly char [ ] trimChars = new char [ ] { ' ' } ;
113+ private static readonly char [ ] dirSepChars = new [ ] { '/' , '\\ ' } ;
111114
112115 // Options
113116 private string encodingName ;
@@ -467,8 +470,11 @@ private void ProcessFile(string basePath, string sourceFile, string localizedOut
467470 if ( ! titles . TryAdd ( key , new TitleInfo ( WebUtility . HtmlDecode ( topicTitle ) ,
468471 WebUtility . HtmlDecode ( tocTitle ) , sourceFile ) ) )
469472 {
470- currentBuild . ReportWarning ( "SHE0004" , "The key '{0}' used for '{1}' is already in use by " +
471- "'{2}'. '{1}' will be ignored." , key , sourceFile , titles [ key ] . File ) ;
473+ lock ( lockObject )
474+ {
475+ currentBuild . ReportWarning ( "SHE0004" , "The key '{0}' used for '{1}' is already in use by " +
476+ "'{2}'. '{1}' will be ignored." , key , sourceFile , titles [ key ] . File ) ;
477+ }
472478 }
473479
474480 // Extract K index keywords
@@ -489,7 +495,7 @@ private void ProcessFile(string basePath, string sourceFile, string localizedOut
489495 if ( match . Success )
490496 {
491497 keyword . MainEntry = term . Substring ( 0 , match . Index ) ;
492- keyword . SubEntry = term . Substring ( match . Index + 1 ) . TrimStart ( new char [ ] { ' ' } ) ;
498+ keyword . SubEntry = term . Substring ( match . Index + 1 ) . TrimStart ( trimChars ) ;
493499 }
494500 else
495501 keyword . MainEntry = term ;
@@ -568,15 +574,15 @@ private void WriteHelp1xTableOfContents()
568574 // Remove any sub-folder if present as the titles are keyed on the name alone
569575 if ( ! String . IsNullOrWhiteSpace ( key ) )
570576 {
571- int dirSep = key . IndexOfAny ( new [ ] { '/' , ' \\ ' } ) ;
577+ int dirSep = key . IndexOfAny ( dirSepChars ) ;
572578
573579 if ( dirSep != - 1 )
574580 key = key . Substring ( dirSep + 1 ) ;
575581 }
576582
577- if ( ! String . IsNullOrWhiteSpace ( key ) && titles . ContainsKey ( key ) )
583+ if ( ! String . IsNullOrWhiteSpace ( key ) && titles . TryGetValue ( key , out TitleInfo value ) )
578584 {
579- titleInfo = titles [ key ] ;
585+ titleInfo = value ;
580586 title = titleInfo . TocTitle ;
581587 htmlFile = titleInfo . File . Substring ( baseFolderLength ) ;
582588 }
@@ -636,7 +642,7 @@ private void WriteHelp1xTableOfContents()
636642 /// <param name="writer">The writer to which the line is saved</param>
637643 /// <param name="indentCount">The amount of indent to use</param>
638644 /// <param name="value">The value to write</param>
639- private static void WriteContentLine ( TextWriter writer , int indentCount , string value )
645+ private static void WriteContentLine ( StreamWriter writer , int indentCount , string value )
640646 {
641647 writer . WriteLine ( ) ;
642648
@@ -792,15 +798,15 @@ private void WriteWebsiteTableOfContents()
792798 // Remove any sub-folder if present as the titles are keyed on the name alone
793799 if ( ! String . IsNullOrWhiteSpace ( key ) )
794800 {
795- int dirSep = key . IndexOfAny ( new [ ] { '/' , ' \\ ' } ) ;
801+ int dirSep = key . IndexOfAny ( dirSepChars ) ;
796802
797803 if ( dirSep != - 1 )
798804 key = key . Substring ( dirSep + 1 ) ;
799805 }
800806
801- if ( ! String . IsNullOrWhiteSpace ( key ) && titles . ContainsKey ( key ) )
807+ if ( ! String . IsNullOrWhiteSpace ( key ) && titles . TryGetValue ( key , out TitleInfo value ) )
802808 {
803- titleInfo = titles [ key ] ;
809+ titleInfo = value ;
804810 title = titleInfo . TocTitle ;
805811 htmlFile = titleInfo . File . Substring ( baseFolderLength ) . Replace ( '\\ ' , '/' ) ;
806812 }
0 commit comments