File size: 1,054 Bytes
1521ef5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Text utility functions.
Provides common functionality for working with text.
"""

def merge_descriptions(old_desc, new_desc, replace=False):
    """
    Merges or replaces text descriptions.
    
    Args:
        old_desc: The original description text
        new_desc: The new description text
        replace: If True, replace the old description with the new one.
                If False, merge them with a divider.
        
    Returns:
        A merged or replaced description string
    """
    old_desc = old_desc.strip() if old_desc else ""
    new_desc = new_desc.strip() if new_desc else ""
    
    if not old_desc:
        return new_desc
    if not new_desc:
        return old_desc
        
    if replace:
        return new_desc
    else:
        return f"{old_desc}\n\n---\n{new_desc}"

def _serialize_unknown_type(obj):
    """
    Serializes an object of unknown type to a string.
    
    Args:
        obj: The object to serialize
        
    Returns:
        A string representation of the object
    """
    return str(obj)