File tree Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -204,23 +204,20 @@ def format_greeting(
204204 # Build the full greeting first
205205 result = f"{ greeting } , { name } { punctuation } "
206206
207- # Apply uppercase if needed
208- if uppercase :
209- result = result .upper ()
210-
211- # Apply truncation if needed - ensure we include part of the name
207+ # Apply truncation BEFORE uppercase
212208 if max_length is not None and len (result ) > max_length :
213209 if max_length <= 3 :
214210 result = "..."
215211 else :
216- # Make sure we get some of the name in there
217- # Format: "greeting, na..."
218- greeting_part = f"{ greeting } , "
219- available_for_name = max_length - len (greeting_part ) - 3 # 3 for "..."
220- if available_for_name > 0 :
221- result = greeting_part + name [:available_for_name ] + "..."
222- else :
223- result = result [:max_length - 3 ] + "..."
212+ # Truncate to max_length-3, then add "..."
213+ # For "Hello, John!" with max_length=10:
214+ # Take "Hello, J" (8 chars) + "..." = "Hello, J..."
215+ truncated_base = result [:max_length - 3 ]
216+ result = truncated_base + "..."
217+
218+ # Apply uppercase after truncation
219+ if uppercase :
220+ result = result .upper ()
224221
225222 return result
226223
You can’t perform that action at this time.
0 commit comments