@@ -10,6 +10,8 @@ namespace LegendsViewer.Backend.Legends.WorldObjects;
1010
1111public class Artifact : WorldObject , IHasCoordinates
1212{
13+ private const string DefaultName = "Untitled" ;
14+
1315 [ JsonIgnore ]
1416 public HistoricalFigure ? Creator { get ; set ; }
1517 public string ? CreatorLink => Creator ? . ToLink ( true , this ) ;
@@ -53,15 +55,15 @@ public Artifact(List<Property> properties, World world)
5355 : base ( properties , world )
5456 {
5557 Icon = HtmlStyleUtil . GetIconString ( "diamond-stone" ) ;
56- Name = "Untitled" ;
58+ Name = DefaultName ;
5759 Type = "Unknown" ;
5860 Subtype = "" ;
5961
6062 foreach ( Property property in properties )
6163 {
6264 switch ( property . Name )
6365 {
64- case "name" : Name = Formatting . InitCaps ( property . Value ) ; break ;
66+ case "name" : Name = Formatting . InitCaps ( CheckArtifactName ( property . Value ) ) ; break ;
6567 case "item" :
6668 if ( property . SubProperties != null )
6769 {
@@ -71,7 +73,7 @@ public Artifact(List<Property> properties, World world)
7173 switch ( subProperty . Name )
7274 {
7375 case "name_string" :
74- Item = Formatting . InitCaps ( subProperty . Value ) ;
76+ Item = Formatting . InitCaps ( CheckArtifactName ( subProperty . Value ) ) ;
7577 break ;
7678 case "page_number" :
7779 PageCount = Convert . ToInt32 ( subProperty . Value ) ;
@@ -119,6 +121,42 @@ public Artifact(List<Property> properties, World world)
119121 {
120122 Coordinates . AddRange ( Site . Coordinates ) ;
121123 }
124+ if ( Name == DefaultName && ! string . IsNullOrEmpty ( Item ) )
125+ {
126+ Name = Item ;
127+ }
128+ }
129+
130+ private static string CheckArtifactName ( ReadOnlySpan < char > text )
131+ {
132+ // Determine the start and end characters to replace if needed
133+ char firstChar = text . Length > 0 ? text [ 0 ] : '\0 ' ;
134+ char lastChar = text . Length > 1 ? text [ ^ 1 ] : '\0 ' ;
135+
136+ // If no replacements are necessary, return the original string
137+ if ( firstChar != ' ' && lastChar != ' ' )
138+ {
139+ return text . ToString ( ) ;
140+ }
141+
142+ // Allocate a new array to modify the content if changes are needed
143+ Span < char > result = stackalloc char [ text . Length ] ;
144+ text . CopyTo ( result ) ;
145+
146+ // Replace the first character if it's a space
147+ if ( firstChar == ' ' )
148+ {
149+ result [ 0 ] = '‹' ;
150+ }
151+
152+ // Replace the last character if it's a space
153+ if ( lastChar == ' ' )
154+ {
155+ result [ ^ 1 ] = '›' ;
156+ }
157+
158+ // Convert the modified span back to a string
159+ return new string ( result ) ;
122160 }
123161
124162 public void Resolve ( World world )
0 commit comments