芯方式

电话号码间显示连字符号“-”

0
阅读(208) 评论(0)

[DESCRIPTION]
需要在输入电话号码后,根据North American hyphenation rule在电话号码间显示连字符号"-",比如在输入12345后
,手机会显示成1-234-5;
[SOLUTION]ICfans
此方法适用于:09A版本
请参考下面的代码修改实现:
1) 要先实现加确“-“的算法;
/*********************************************
*函数名: mmi_phb_add_character_for_ hyphenation
*功能: 改变电话号码格式,使其包含'-'
*输入:
* input: 打算改变的字串
* output: 改变之后的字串
* inchar: 刚刚输入的字符
*输出;
* output: 改变后的字串
*author: mlc
*data: 2010/02/09
*************************************************/
void mmi_phb_add_character_for_ hyphenation(char * input, char *output, char *inchar)
{
int i;
int j;
int nDashNum = 0;
int nStrlen = 0;
int index = 0;
int nNum = 0;
assert( input != NULL);
assert( output != NULL);
nDashNum = getDashInstring(input);
nStrlen = strlen(input);
if(input[0]<'0'||input[0]>'9')
return;
if( NULL == inchar) //phbook用来显示用的
{
if( '0' == input[0] )
{
memcpy(output, input, nStrlen);
output[nStrlen] = '\0';
return;
}
else if( nStrlen <=4)
{
memcpy(output, input, nStrlen);
output[nStrlen] = '\0';
return;
}
else if( nDashNum >= 3)
{
memcpy(output, input, strlen(input) );
return;
}
else if( 2 == nDashNum )
{
index = 0;
memcpy(output, input, strlen(input));
if( input[0] != '1')
{
return;
}
else
{
for(i = 0; input[i] != '\0'; i++ )
{
if( '-' == input[i] )
index++;
if( 2 == index )
break;
}
i++;
if( strlen(&input[i]) <=4)///////////////////////
{
return;
}
else
{
output[strlen(input) - 2 ] = '-';
output[strlen(input)-1] = input[strlen(input) - 2 ];
output[strlen(input) ] = input[strlen(input) - 1];
output[strlen(input) +1 ] = input[strlen(input) ];
output[strlen(input) +1 +1] = '\0';
return;
}
}
}
else if( 1 == nDashNum)
{
index = 0;
memcpy(output, input, strlen(input));
for(i = 0; input[i] != '\0'; i++ )
{
if( '-' == input[i] )
index++;
if( 1 == index )
break;
}
i++;
if( strlen(&input[i]) <= 4 )////////////////////
{
return;
}
else
{
output[strlen(input) - 2] = '-';
output[strlen(input) -1] = input[strlen(input) - 2];
output[strlen(input)] = input[strlen(input) - 1];
output[strlen(input) + 1 ] = input[strlen(input) ];
output[strlen(input) +1 + 1] = '\0';
return;
}
}
else
{
if( '1' == input[0] )
{
output[0] = input[0];
output[1] = '-';
i = 1;
j = 2;
for(i; nNum < 3; i++)
{
output[j++] = input[i];
nNum++;
}
output[j++] = '-';
nNum = 0;
for(i; input[i] != '\0'; i++)
{
output[j++] = input[i];
nNum++;
if ( getDashInstring(output) < 3 )
{
if( ( 3 == nNum ) && ( strlen(&input[i+1]) >=2 ))////////////////////////
{
output[j++] = '-';
nNum = 0;
}
}
}
}
else
{
i = 0;
j = 0;
for(i; input[i] != '\0'; i++)
{
output[j] = input[i];
j++;
nNum++;
if ( getDashInstring(output) < 2 )
{
if( ( 3 == nNum ) && ( strlen(&input[i+1]) >=2 ))////////////////////////
{
output[j] = '-';
j++;
nNum = 0;
}
}
}
}
output[j] = '\0';
return;
}
}
else //用来拨号输入的
{
if( nDashNum >= 3)
{
memcpy(output, input, strlen(input) );
output[strlen(input)] = *inchar;
output[strlen(input)+1] = '\0';
return;
}
else if( 2 == nDashNum )
{
index = 0;
memcpy(output, input, strlen(input));
if( input[0] != '1')
{
output[strlen(input) ] = *inchar;
output[strlen(input) +1 ] = '\0';
return;
}
else
{
for(i = 0; input[i] != '\0'; i++ )
{
if( '-' == input[i] )
index++;
if( 2 == index )
break;
}
i++;
if( strlen(&input[i]) <=3)///////////////////////
{
output[strlen(input)] = *inchar;
output[strlen(input) + 1 ] = '\0';
return;
}
else
{
output[strlen(input) - 1 ] = '-';
output[strlen(input)] = input[strlen(input) - 1 ];
output[strlen(input) + 1 ] = *inchar;
output[strlen(input) +1 + 1] = '\0';
return;
}
}
}
else if( 1 == nDashNum)
{
index = 0;
memcpy(output, input, strlen(input));
for(i = 0; input[i] != '\0'; i++ )
{
if( '-' == input[i] )
index++;
if( 1 == index )
break;
}
i++;
if( strlen(&input[i]) <= 3 )////////////////////
{
output[strlen(input)] = *inchar;
output[strlen(input) + 1 ] = '\0';
return;
}
else
{
output[strlen(input) - 1] = '-';
output[strlen(input)] = input[strlen(input) - 1];
output[strlen(input) + 1 ] = *inchar;
output[strlen(input) +1 + 1] = '\0';
return;
}
}
else //nDashNum == 0
{
memcpy(output, input, strlen(input));
if(strlen(input) < 4)
{
output[strlen(input)] = *inchar;
output[strlen(input) + 1 ] = '\0';
return;
}
else if( '1' != input[0] )
{
memcpy( output, input, 3);
output[3] = '-';
memcpy(output + 4, input+3, 1 );
output[5] = *inchar;
output[6] = '\0';
return;
}
else if( '1' == input[0] )
{
output[0] = input[0];
output[1] = '-';
memcpy(output + 2, input +1, 3);
output[5] = '-';
output[6] = *inchar;
output[7] = '\0';
return;
}
}
}
}
void change_text_for_phonebook_number(single_line_input_box *b)
{
半导体社区