GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_utility_string_to_unicode.c Lines: 10 10 100.0 %
Date: 2026-03-06 18:57:10 Branches: 2 2 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   Utility                                                             */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
24
/* Include necessary system files.  */
25
26
#define UX_SOURCE_CODE
27
28
#include "ux_api.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _ux_utility_string_to_unicode                       PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Chaoqiong Xiao, Microsoft Corporation                               */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function converts a ascii string to a unicode string.          */
44
/*                                                                        */
45
/*    Note:                                                               */
46
/*    The unicode string length (including NULL-terminator) is limited by */
47
/*    length in a byte, so max ascii string length must be no more than   */
48
/*    254 (NULL-terminator excluded). Only first 254 characters           */
49
/*    are converted if the string is too long.                            */
50
/*    The buffer of destination must have enough space for result, at     */
51
/*    least 1 + (strlen(source) + 1) * 2 bytes.                           */
52
/*                                                                        */
53
/*  INPUT                                                                 */
54
/*                                                                        */
55
/*    source                                Ascii String                  */
56
/*    destination                           Unicode String                */
57
/*                                                                        */
58
/*  OUTPUT                                                                */
59
/*                                                                        */
60
/*    none                                                                */
61
/*                                                                        */
62
/*  CALLS                                                                 */
63
/*                                                                        */
64
/*    _ux_utility_string_length_check       Check and return C string     */
65
/*                                          length                        */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    USBX Components                                                     */
70
/*                                                                        */
71
/**************************************************************************/
72
53
VOID  _ux_utility_string_to_unicode(UCHAR *source, UCHAR *destination)
73
{
74
75
UINT   string_length;
76
77
    /* Get the ascii string length, when there is error length is not modified so max length is used.  */
78
53
    string_length = 254;
79
53
    _ux_utility_string_length_check(source, &string_length, 254);
80
81
    /* Set the length of the string as the first byte of the unicode string.
82
       The length is casted as a byte since Unicode strings cannot be more than 255 chars.  */
83
53
    *destination++ = (UCHAR)(string_length + 1);
84
85
679
    while(string_length--)
86
    {
87
        /* First character is from the source.  */
88
626
        *destination++ = *source++;
89
90
        /* Second character of unicode word is 0.  */
91
626
        *destination++ = 0;
92
    }
93
94
    /* Finish with a 0.  */
95
53
    *destination++ = 0;
96
97
    /* Finish with a 0.  */
98
53
    *destination++ = 0;
99
100
    /* We are done.  */
101
53
    return;
102
}
103