1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_misc/lv_txt.c

563 lines
17 KiB
C
Raw Normal View History

2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* @file lv_text.c
2017-11-23 20:42:14 +01:00
*
*/
/*********************
* INCLUDES
*********************/
2017-11-26 11:38:28 +01:00
#include "lv_txt.h"
2017-11-26 23:57:39 +01:00
#include "../../lv_conf.h"
2017-11-23 20:42:14 +01:00
#include "lv_math.h"
/*********************
* DEFINES
*********************/
2017-11-24 17:48:47 +01:00
#define NO_BREAK_FOUND UINT32_MAX
2017-11-23 20:42:14 +01:00
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2017-11-24 17:48:47 +01:00
static bool is_break_char(uint32_t letter);
2017-11-23 20:42:14 +01:00
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Get size of a text
* @param size_res pointer to a 'point_t' variable to store the result
* @param text pointer to a text
* @param font pinter to font of the text
* @param letter_space letter space of the text
* @param txt.line_space line space of the text
* @param flags settings for the text from 'txt_flag_t' enum
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
*/
2017-11-24 17:48:47 +01:00
void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font,
lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag)
2017-11-23 20:42:14 +01:00
{
2017-11-23 20:42:14 +01:00
size_res->x = 0;
size_res->y = 0;
if(text == NULL) return;
if(font == NULL) return;
2017-11-24 17:48:47 +01:00
if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
2017-11-23 20:42:14 +01:00
uint32_t line_start = 0;
uint32_t new_line_start = 0;
2017-11-23 21:28:36 +01:00
lv_coord_t act_line_length;
uint8_t letter_height = lv_font_get_height_scale(font);
2017-11-23 20:42:14 +01:00
/*Calc. the height and longest line*/
while (text[line_start] != '\0') {
2017-11-24 17:48:47 +01:00
new_line_start += lv_txt_get_next_line(&text[line_start], font, letter_space, max_width, flag);
2017-11-23 20:42:14 +01:00
size_res->y += letter_height ;
size_res->y += line_space;
/*Calculate the the longest line*/
2017-11-24 17:48:47 +01:00
act_line_length = lv_txt_get_width(&text[line_start], new_line_start - line_start,
2017-11-23 20:42:14 +01:00
font, letter_space, flag);
2017-11-24 17:48:47 +01:00
size_res->x = LV_MATH_MAX(act_line_length, size_res->x);
2017-11-23 20:42:14 +01:00
line_start = new_line_start;
}
if(line_start != 0 && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) {
size_res->y += letter_height + line_space;
}
/*Correction with the last line space or set the height manually if the text is empty*/
if(size_res->y == 0) size_res->y = letter_height;
else size_res->y -= line_space;
}
/**
* Get the next line of text. Check line length and break chars too.
* @param txt a '\0' terminated string
* @param font pointer to a font
* @param letter_space letter space
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
* @param flags settings for the text from 'txt_flag_type' enum
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different)
*/
2017-11-24 17:48:47 +01:00
uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag)
2017-11-23 20:42:14 +01:00
{
if(txt == NULL) return 0;
if(font == NULL) return 0;
2017-11-24 17:48:47 +01:00
if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
2017-11-23 20:42:14 +01:00
uint32_t i = 0;
lv_coord_t cur_w = 0;
2017-11-24 17:48:47 +01:00
uint32_t last_break = NO_BREAK_FOUND;
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
2017-11-23 20:42:14 +01:00
uint32_t letter = 0;
2017-11-23 20:42:14 +01:00
while(txt[i] != '\0') {
2017-11-24 17:48:47 +01:00
letter = lv_txt_utf8_next(txt, &i);
2017-11-23 20:42:14 +01:00
/*Handle the recolor command*/
2017-11-24 17:48:47 +01:00
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
if(lv_txt_is_cmd(&cmd_state, letter) != false) {
2017-11-23 20:42:14 +01:00
continue; /*Skip the letter is it is part of a command*/
}
}
/*Check for new line chars*/
2017-11-24 17:48:47 +01:00
if((flag & LV_TXT_FLAG_NO_BREAK) == 0 && (letter == '\n' || letter == '\r')) {
2017-11-23 20:42:14 +01:00
/*Handle \r\n as well*/
uint32_t i_tmp = i;
2017-11-24 17:48:47 +01:00
uint32_t letter_next = lv_txt_utf8_next(txt, &i_tmp);
2017-11-23 20:42:14 +01:00
if(letter == '\r' && letter_next == '\n') i = i_tmp;
return i; /*Return with the first letter of the next line*/
} else { /*Check the actual length*/
cur_w += lv_font_get_width_scale(font, letter);
2017-11-23 20:42:14 +01:00
/*If the txt is too long then finish, this is the line end*/
if(cur_w > max_width) {
2017-11-23 20:42:14 +01:00
/*If this a break char then break here.*/
2017-11-24 17:48:47 +01:00
if(is_break_char(letter)) {
2017-11-23 20:42:14 +01:00
/* Now 'i' points to the next char because of txt_utf8_next()
* But we need the first char of the next line so keep it.
* Hence do nothing here*/
}
/*If already a break character is found, then break there*/
if(last_break != NO_BREAK_FOUND ) {
2017-11-23 20:42:14 +01:00
i = last_break;
} else {
/* Now this character is out of the area so it will be first character of the next line*/
/* But 'i' already points to the next character (because of lv_txt_utf8_next) step beck one*/
2017-11-24 17:48:47 +01:00
lv_txt_utf8_prev(txt, &i);
2017-11-23 20:42:14 +01:00
}
/* Do not let to return without doing nothing.
* Find at least one character (Avoid infinite loop )*/
2017-11-24 17:48:47 +01:00
if(i == 0) lv_txt_utf8_next(txt, &i);
2017-11-23 20:42:14 +01:00
return i;
}
/*If this char still can fit to this line then check if
* txt can be broken here later */
2017-11-24 17:48:47 +01:00
else if(is_break_char(letter)) {
2017-11-23 20:42:14 +01:00
last_break = i; /*Save the first char index after break*/
}
}
cur_w += letter_space;
2017-11-23 20:42:14 +01:00
}
return i;
}
/**
* Give the length of a text with a given font
* @param txt a '\0' terminate string
* @param length length of 'txt' in bytes
* @param font pointer to a font
* @param letter_space letter space
* @param flags settings for the text from 'txt_flag_t' enum
* @return length of a char_num long text
*/
2017-11-24 17:48:47 +01:00
lv_coord_t lv_txt_get_width(const char * txt, uint16_t length,
const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag)
2017-11-23 20:42:14 +01:00
{
if(txt == NULL) return 0;
if(font == NULL) return 0;
uint32_t i = 0;
2017-11-23 21:28:36 +01:00
lv_coord_t width = 0;
2017-11-24 17:48:47 +01:00
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
2017-11-23 20:42:14 +01:00
uint32_t letter;
if(length != 0) {
while(i < length) {
2017-11-24 17:48:47 +01:00
letter = lv_txt_utf8_next(txt, &i);
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
if(lv_txt_is_cmd(&cmd_state, letter) != false) {
2017-11-23 20:42:14 +01:00
continue;
}
}
2017-11-23 21:28:36 +01:00
width += lv_font_get_width_scale(font, letter);
2017-11-23 20:42:14 +01:00
width += letter_space;
}
2017-11-23 20:42:14 +01:00
/*Trim closing spaces. Important when the text is aligned to the middle */
for(i = length - 1; i > 0; i--) {
if(txt[i] == ' ') {
2017-11-23 21:28:36 +01:00
width -= lv_font_get_width_scale(font, txt[i]);
2017-11-23 20:42:14 +01:00
width -= letter_space;
} else {
break;
}
}
}
return width;
}
/**
* Check next character in a string and decide if the character is part of the command or not
* @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing
* (Initied. to TXT_CMD_STATE_WAIT )
* @param c the current character
* @return true: the character is part of a command and should not be written,
* false: the character should be written
*/
2017-11-24 17:48:47 +01:00
bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c)
2017-11-23 20:42:14 +01:00
{
bool ret = false;
2017-12-02 20:43:50 +01:00
if(c == (uint32_t)LV_TXT_COLOR_CMD[0]) {
2017-11-24 17:48:47 +01:00
if(*state == LV_TXT_CMD_STATE_WAIT) { /*Start char*/
*state = LV_TXT_CMD_STATE_PAR;
2017-11-23 20:42:14 +01:00
ret = true;
2017-11-24 17:48:47 +01:00
} else if(*state == LV_TXT_CMD_STATE_PAR) { /*Other start char in parameter is escaped cmd. char */
*state = LV_TXT_CMD_STATE_WAIT;
}else if(*state == LV_TXT_CMD_STATE_IN) { /*Command end */
*state = LV_TXT_CMD_STATE_WAIT;
2017-11-23 20:42:14 +01:00
ret = true;
}
}
/*Skip the color parameter and wait the space after it*/
2017-11-24 17:48:47 +01:00
if(*state == LV_TXT_CMD_STATE_PAR) {
2017-11-23 20:42:14 +01:00
if(c == ' ') {
2017-11-24 17:48:47 +01:00
*state = LV_TXT_CMD_STATE_IN; /*After the parameter the text is in the command*/
2017-11-23 20:42:14 +01:00
}
ret = true;
}
return ret;
}
/**
* Insert a string into an other
* @param txt_buf the original text (must be big enough for the result text)
* @param pos position to insert. Expressed in character index and not byte index (Different in UTF-8)
* 0: before the original text, 1: after the first char etc.
* @param ins_txt text to insert
*/
2017-11-24 17:48:47 +01:00
void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
2017-11-23 20:42:14 +01:00
{
uint32_t old_len = strlen(txt_buf);
uint32_t ins_len = strlen(ins_txt);
uint32_t new_len = ins_len + old_len;
2017-11-26 14:39:22 +01:00
#if LV_TXT_UTF8 != 0
2017-11-23 20:42:14 +01:00
pos = txt_utf8_get_byte_id(txt_buf, pos); /*Convert to byte index instead of letter index*/
#endif
/*Copy the second part into the end to make place to text to insert*/
2017-12-02 20:43:50 +01:00
uint32_t i;
2017-11-23 20:42:14 +01:00
for(i = new_len; i >= pos + ins_len; i--){
txt_buf[i] = txt_buf[i - ins_len];
}
/* Copy the text into the new space*/
memcpy(txt_buf + pos, ins_txt, ins_len);
}
/**
* Delete a part of a string
* @param txt string to modify
* @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.)
* @param len number of characters to delete
*/
2017-11-24 17:48:47 +01:00
void lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
2017-11-23 20:42:14 +01:00
{
uint32_t old_len = strlen(txt);
2017-11-26 14:39:22 +01:00
#if LV_TXT_UTF8 != 0
2017-11-23 20:42:14 +01:00
pos = txt_utf8_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/
len = txt_utf8_get_byte_id(&txt[pos], len);
#endif
/*Copy the second part into the end to make place to text to insert*/
uint32_t i;
for(i = pos; i <= old_len - len; i++){
txt[i] = txt[i+len];
}
}
/**
* Give the size of an UTF-8 coded character
* @param c A character where the UTF-8 character starts
* @return length of the UTF-8 character (1,2,3 or 4). O on invalid code
*/
2017-11-24 17:48:47 +01:00
uint8_t lv_txt_utf8_size(uint8_t c)
2017-11-23 20:42:14 +01:00
{
if((c & 0b10000000) == 0) return 1;
else if((c & 0b11100000) == 0b11000000) return 2;
else if((c & 0b11110000) == 0b11100000) return 3;
else if((c & 0b11111000) == 0b11110000) return 4;
return 0;
}
/**
* Convert an Unicode letter to UTF-8.
* @param letter_uni an Unicode letter
* @return UTF-8 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű')
*/
uint32_t txt_unicode_to_utf8(uint32_t letter_uni)
{
if(letter_uni < 128) return letter_uni;
uint8_t bytes[4];
if (letter_uni < 0x0800) {
bytes[0] = ((letter_uni>>6) & 0x1F) | 0xC0;
bytes[1] = ((letter_uni>>0) & 0x3F) | 0x80;
bytes[2] = 0;
bytes[3] = 0;
}
else if (letter_uni < 0x010000) {
bytes[0] = ((letter_uni>>12) & 0x0F) | 0xE0;
bytes[1] = ((letter_uni>>6) & 0x3F) | 0x80;
bytes[2] = ((letter_uni>>0) & 0x3F) | 0x80;
bytes[3] = 0;
}
else if (letter_uni < 0x110000) {
bytes[0] = ((letter_uni>>18) & 0x07) | 0xF0;
bytes[1] = ((letter_uni>>12) & 0x3F) | 0x80;
bytes[2] = ((letter_uni>>6) & 0x3F) | 0x80;
bytes[3] = ((letter_uni>>0) & 0x3F) | 0x80;
}
2017-11-26 23:57:39 +01:00
uint32_t *res_p = (uint32_t *)bytes;
return *res_p;
2017-11-23 20:42:14 +01:00
}
/**
* Decode an UTF-8 character from a string.
* @param txt pointer to '\0' terminated string
2017-11-24 17:48:47 +01:00
* @param i start byte index in 'txt' where to start.
* After call it will point to the next UTF-8 char in 'txt'.
* NULL to use txt[0] as index
2017-11-23 20:42:14 +01:00
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
2017-11-24 17:48:47 +01:00
uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i)
2017-11-23 20:42:14 +01:00
{
2017-11-26 14:39:22 +01:00
#if LV_TXT_UTF8 == 0
2017-11-23 20:42:14 +01:00
if(i == NULL) return txt[1]; /*Get the next char */
uint8_t letter = txt[*i] ;
(*i)++;
return letter;
#else
/* Unicode to UTF-8
* 00000000 00000000 00000000 0xxxxxxx -> 0xxxxxxx
* 00000000 00000000 00000yyy yyxxxxxx -> 110yyyyy 10xxxxxx
* 00000000 00000000 zzzzyyyy yyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx
* 00000000 000wwwzz zzzzyyyy yyxxxxxx -> 11110www 10zzzzzz 10yyyyyy 10xxxxxx
* */
uint32_t result = 0;
/*Dummy 'i' pointer is required*/
uint32_t i_tmp = 0;
if(i == NULL) i = &i_tmp;
/*Normal ASCII*/
if((txt[*i] & 0x80) == 0) {
result = txt[*i];
(*i)++;
}
/*Real UTF-8 decode*/
else {
/*2 bytes UTF-8 code*/
if((txt[*i] & 0b11100000) == 0b11000000) {
2017-11-26 23:57:39 +01:00
result = (uint32_t)(txt[*i] & 0b00011111) << 6;
2017-11-23 20:42:14 +01:00
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (txt[*i] & 0b00111111);
(*i)++;
}
/*3 bytes UTF-8 code*/
else if((txt[*i] & 0b11110000) == 0b11100000) {
2017-11-26 23:57:39 +01:00
result = (uint32_t)(txt[*i] & 0b00001111) << 12;
2017-11-23 20:42:14 +01:00
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
2017-11-26 23:57:39 +01:00
result += (uint32_t)(txt[*i] & 0b00111111) << 6;
2017-11-23 20:42:14 +01:00
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
result += (txt[*i] & 0b00111111);
(*i)++;
}
/*3 bytes UTF-8 code*/
else if((txt[*i] & 0b11111000) == 0b11110000) {
2017-11-26 23:57:39 +01:00
result = (uint32_t)(txt[*i] & 0b00001111) << 18;
2017-11-23 20:42:14 +01:00
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
2017-11-26 23:57:39 +01:00
result += (uint32_t)(txt[*i] & 0b00111111) << 12;
2017-11-23 20:42:14 +01:00
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
2017-11-26 23:57:39 +01:00
result += (uint32_t)(txt[*i] & 0b00111111) << 6;
2017-11-23 20:42:14 +01:00
(*i)++;
if((txt[*i] & 0b11000000) != 0b10000000) return 0; /*Invalid UTF-8 code*/
2017-11-26 23:57:39 +01:00
result += (uint32_t)(txt[*i] & 0b00111111) << 6;
2017-11-23 20:42:14 +01:00
(*i)++;
} else {
(*i)++; /*Not UTF-8 char. Go the next.*/
}
}
return result;
#endif
}
/**
* Get previous UTF-8 character form a string.
* @param txt pointer to '\0' terminated string
2017-11-24 17:48:47 +01:00
* @param i start byte index in 'txt' where to start. After the call it will point to the previous UTF-8 char in 'txt'.
2017-11-23 20:42:14 +01:00
* @return the decoded Unicode character or 0 on invalid UTF-8 code
*/
2017-11-24 17:48:47 +01:00
uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i)
2017-11-23 20:42:14 +01:00
{
2017-11-26 14:39:22 +01:00
#if LV_TXT_UTF8 == 0
2017-11-24 17:48:47 +01:00
if(i == NULL) return *(txt- 1); /*Get the prev. char */
(*i)--;
2017-11-26 11:38:28 +01:00
uint8_t letter = txt[*i] ;
2017-11-24 17:48:47 +01:00
return letter;
#else
2017-11-23 20:42:14 +01:00
uint8_t c_size;
uint8_t cnt = 0;
/*Try to find a !0 long UTF-8 char by stepping one character back*/
2017-11-24 17:48:47 +01:00
(*i)--;
2017-11-23 20:42:14 +01:00
do {
if(cnt >= 4) return 0; /*No UTF-8 char found before the initial*/
2017-11-24 17:48:47 +01:00
c_size = lv_txt_utf8_size(txt[*i]);
2017-11-23 20:42:14 +01:00
if(c_size == 0) {
2017-11-24 17:48:47 +01:00
if(*i != 0) (*i)--;
2017-11-23 20:42:14 +01:00
else return 0;
}
cnt++;
} while(c_size == 0);
2017-11-24 17:48:47 +01:00
uint32_t i_tmp = *i;
uint32_t letter = lv_txt_utf8_next(txt, &i_tmp); /*Character found, get it*/
2017-11-23 20:42:14 +01:00
return letter;
2017-11-24 17:48:47 +01:00
#endif
2017-11-23 20:42:14 +01:00
}
/**
* Convert a character index (in an UTF-8 text) to byte index.
2017-11-24 17:48:47 +01:00
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
2017-11-23 20:42:14 +01:00
* @param txt a '\0' terminated UTF-8 string
2017-11-24 17:48:47 +01:00
* @param utf8_id character index
2017-11-23 20:42:14 +01:00
* @return byte index of the 'utf8_id'th letter
*/
uint32_t txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id)
{
2017-11-26 14:39:22 +01:00
#if LV_TXT_UTF8 == 0
2017-11-23 20:42:14 +01:00
return utf8_id; /*In Non UTF-8 no difference*/
#else
uint32_t i;
uint32_t byte_cnt = 0;
for(i = 0; i < utf8_id; i++) {
2017-11-24 17:48:47 +01:00
byte_cnt += lv_txt_utf8_size(txt[byte_cnt]);
2017-11-23 20:42:14 +01:00
}
return byte_cnt;
#endif
}
/**
* Convert a byte index (in an UTF-8 text) to character index.
2017-11-24 17:48:47 +01:00
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
2017-11-23 20:42:14 +01:00
* @param txt a '\0' terminated UTF-8 string
* @param byte_id byte index
* @return character index of the letter at 'byte_id'th position
*/
2017-11-24 17:48:47 +01:00
uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id)
2017-11-23 20:42:14 +01:00
{
2017-11-26 14:39:22 +01:00
#if LV_TXT_UTF8 == 0
2017-11-23 20:42:14 +01:00
return byte_id; /*In Non UTF-8 no difference*/
#else
uint32_t i = 0;
uint32_t char_cnt = 0;
while(i < byte_id) {
2017-11-24 17:48:47 +01:00
lv_txt_utf8_next(txt, &i); /*'i' points to the next letter so use the prev. value*/
2017-11-23 20:42:14 +01:00
char_cnt++;
}
return char_cnt;
#endif
}
/**
* Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled.
* E.g.: "ÁBC" is 3 characters (but 4 bytes)
* @param txt a '\0' terminated char string
* @return number of characters
*/
2017-11-24 17:48:47 +01:00
uint32_t lv_txt_get_length(const char * txt)
2017-11-23 20:42:14 +01:00
{
2017-11-26 14:39:22 +01:00
#if LV_TXT_UTF8 == 0
2017-11-23 20:42:14 +01:00
return strlen(txt);
#else
uint32_t len = 0;
uint32_t i = 0;
while(txt[i] != '\0') {
2017-11-24 17:48:47 +01:00
lv_txt_utf8_next(txt, &i);
2017-11-23 20:42:14 +01:00
len++;
}
return len;
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Test if char is break char or not (a text can broken here or not)
* @param letter a letter
* @return false: 'letter' is not break char
*/
2017-11-24 17:48:47 +01:00
static bool is_break_char(uint32_t letter)
2017-11-23 20:42:14 +01:00
{
uint8_t i;
bool ret = false;
/*Compare the letter to TXT_BREAK_CHARS*/
2017-11-26 11:38:28 +01:00
for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) {
2017-12-02 20:43:50 +01:00
if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) {
2017-11-23 20:42:14 +01:00
ret = true; /*If match then it is break char*/
break;
}
}
return ret;
}