-
November 16th, 2017, 02:21 PM
#1
[RESOLVED] Need urgent help, please have mercy on me
Hi All,
I am trying to solve a bug, but is in entirely different area.
I need to fix this very urgently.
The string we can pass to this function can be "5555", "15555". But all of them must be stored in "+15555".
So the code he has written is
Code:
string NormaliseNumber(string & sDialled)
{
string sNormalised;
if (sDialled.empty() == false)
{
if (sDialled.at(0) == '+')
sNormalised = sDialled;
else
{
unsigned int nCodeLen = m_sIntAccessCode.size();
if (nCodeLen > 0 && sDialled.size() >= nCodeLen && sDialled.substr(0, nCodeLen) == m_sIntAccessCode)
sNormalised = "+" + sDialled.substr(nCodeLen);
else
{
nCodeLen = m_sTrunkAccessCode.size();
if (nCodeLen > 0 && sDialled.size() >= nCodeLen && sDialled.substr(0, nCodeLen) == m_sTrunkAccessCode)
sNormalised = "+" + m_sCountryCode + sDialled.substr(nCodeLen);
else if(m_bNoTrunkAccessCode)
{
// American networks do not have trunk access code
// Still we need to normalise it by adding the normal trunk access code
// Which is usually numbers beginning with "0"
string sNewDialled;
if(sDialled.substr(0, m_sCountryCode.size()) == m_sCountryCode)
{
// For numbers in format 1<MSN>
sNewDialled = m_sTrunkAccessCode + sDialled.substr(m_sCountryCode.size(), sDialled.size());
}
else
{
// For numbers in format <MSN>
sNewDialled = m_sTrunkAccessCode + sDialled;
}
if (nCodeLen > 0 && sNewDialled.size() >= nCodeLen && sNewDialled.substr(0, nCodeLen) == m_sTrunkAccessCode)
sNormalised = "+" + m_sCountryCode + sNewDialled.substr(nCodeLen);
}
else
{
sNormalised = sDialled;
}
}
}
}
return sNormalised;
}
could you please help me quickly to fix this..
Last edited by pdk5; December 6th, 2017 at 12:34 PM.
Reason: CODE tags correction
-
November 16th, 2017, 02:40 PM
#2
Re: Need urgent help, please have mercy on me
Well, I tried... but your code snippet is not complete for testing. There is a lot of errors:
Code:
error C2065: 'm_sIntAccessCode': undeclared identifier
error C2228: left of '.size' must have class/struct/union
: note: type is 'unknown-type'
error C2065: 'm_sIntAccessCode': undeclared identifier
error C2065: 'm_sTrunkAccessCode': undeclared identifier
error C2228: left of '.size' must have class/struct/union
: note: type is 'unknown-type'
error C2065: 'm_sTrunkAccessCode': undeclared identifier
error C2065: 'm_sCountryCode': undeclared identifier
error C2065: 'm_bNoTrunkAccessCode': undeclared identifier
error C2065: 'm_sCountryCode': undeclared identifier
error C2228: left of '.size' must have class/struct/union
: note: type is 'unknown-type'
error C2065: 'm_sTrunkAccessCode': undeclared identifier
error C2065: 'm_sCountryCode': undeclared identifier
error C2228: left of '.size' must have class/struct/union
: note: type is 'unknown-type'
error C2065: 'm_sTrunkAccessCode': undeclared identifier
error C2065: 'm_sTrunkAccessCode': undeclared identifier
error C2065: 'm_sCountryCode': undeclared identifier
Victor Nijegorodov
-
November 16th, 2017, 02:43 PM
#3
Re: Need urgent help, please have mercy on me
thanks a lot Victor , this code is directly from my code base..
here, m_sIntAccessCode is false..m_sTrunkAccessCode is 0, m_bNoTrunkAccessCode is true..and sCountryCode is 1
-
November 16th, 2017, 03:39 PM
#4
Re: Need urgent help, please have mercy on me
no. something is wrong in your recent post. because
Code:
error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' (or there is no acceptable conversion)
note: could be 'bool operator ==(const D2D1_RECT_U &,const D2D1_RECT_U &)'
'bool operator ==(const D2D1_SIZE_U &,const D2D1_SIZE_U &)'
'bool operator ==(const DEVPROPCOMPKEY &,const DEVPROPCOMPKEY &)'
bool operator ==(const DEVPROPKEY &,const DEVPROPKEY &)'
'int operator ==(const PROPERTYKEY &,const PROPERTYKEY &)'
'bool operator ==(const GUID &,const GUID &)'
note: or 'bool std::operator ==(const std::error_condition &,const std::error_condition &) noexcept'
note: or 'bool std::operator ==(const std::error_condition &,const std::error_code &) noexcept'
note: or 'bool std::operator ==(const std::error_code &,const std::error_condition &) noexcept'
note: or 'bool std::operator ==(const std::error_code &,const std::error_code &) noexcept'
note: or 'bool std::operator ==(const std::exception_ptr &,std::nullptr_t) throw()'
note: or 'bool std::operator ==(std::nullptr_t,const std::exception_ptr &) throw()'
note: or 'bool std::operator ==(const std::exception_ptr &,const std::exception_ptr &) throw()'
note: while trying to match the argument list '(std::basic_string<char,std::char_traits<char>,std::allocator<char>>, bool)'
error C2228: left of '.size' must have class/struct/union
note: type is 'int'
error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' (or there is no acceptable conversion)
note: could be 'bool operator ==(const D2D1_RECT_U &,const D2D1_RECT_U &)'
note: or 'bool operator ==(const D2D1_SIZE_U &,const D2D1_SIZE_U &)'
note: or 'bool operator ==(const DEVPROPCOMPKEY &,const DEVPROPCOMPKEY &)'
note: or 'bool operator ==(const DEVPROPKEY &,const DEVPROPKEY &)'
note: or 'int operator ==(const PROPERTYKEY &,const PROPERTYKEY &)'
note: or 'bool operator ==(const GUID &,const GUID &)'
note: or 'bool std::operator ==(const std::error_condition &,const std::error_condition &) noexcept'
note: or 'bool std::operator ==(const std::error_condition &,const std::error_code &) noexcept'
...
Victor Nijegorodov
-
November 16th, 2017, 05:04 PM
#5
Re: Need urgent help, please have mercy on me
m_sIntAccessCode is false..m_sTrunkAccessCode is 0
m_sIntAccessCode and m_sTrunkAccessCode are containers so can't have the value false or 0! ?? How are these variable defined (as a string?)?
The string we can pass to this function can be "5555", "15555". But all of them must be stored in "+15555".
There must be more to the requirement of this function than this. Given a string which may or may not start with a 1 and to convert it to start with +1 doesn't require all this code. What is the spec of the function?
Last edited by 2kaud; November 16th, 2017 at 05:11 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 16th, 2017, 05:26 PM
#6
Re: Need urgent help, please have mercy on me
Code:
string m_sCountryCode = "1";
bool m_bNoTrunkAccessCode = true;
string m_sIntAccessCode;
string m_sTrunkAccessCode;
string NormaliseNumber(const string & sDialled)
{
string sNormalised;
if (sDialled.empty() == false)
{
if (sDialled.at(0) == '+')
sNormalised = sDialled;
else
{
unsigned int nCodeLen = m_sIntAccessCode.size();
if (nCodeLen > 0 && sDialled.size() >= nCodeLen && sDialled.substr(0, nCodeLen) == m_sIntAccessCode)
sNormalised = "+" + sDialled.substr(nCodeLen);
else
{
nCodeLen = m_sTrunkAccessCode.size();
if (nCodeLen > 0 && sDialled.size() >= nCodeLen && sDialled.substr(0, nCodeLen) == m_sTrunkAccessCode)
sNormalised = "+" + m_sCountryCode + sDialled.substr(nCodeLen);
else if (m_bNoTrunkAccessCode)
{
// American networks do not have trunk access code
// Still we need to normalise it by adding the normal trunk access code
// Which is usually numbers beginning with "0"
string sNewDialled;
if (sDialled.substr(0, m_sCountryCode.size()) == m_sCountryCode)
{
// For numbers in format 1<MSN>
sNewDialled = m_sTrunkAccessCode + sDialled.substr(m_sCountryCode.size(), sDialled.size());
} else
{
// For numbers in format <MSN>
sNewDialled = m_sTrunkAccessCode + sDialled;
}
//if (nCodeLen > 0 && sNewDialled.size() >= nCodeLen && sNewDialled.substr(0, nCodeLen) == m_sTrunkAccessCode)
sNormalised = "+" + m_sCountryCode + sNewDialled ; //.substr(nCodeLen);
} else
{
sNormalised = sDialled;
}
}
}
}
return sNormalised;
}
int main()
{
cout << NormaliseNumber("5555") << endl;
cout << NormaliseNumber("15555") << endl;;
}
Given the input of 5555 or 15555 then this revised code produces the required output. The changes made are highlighted in red.
I can't say whether it will work for all other required input as there is no other test data.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 6th, 2017, 07:12 AM
#7
Re: Need urgent help, please have mercy on me
@ kaud, thanks a lot for the help.
Actually I was quite busy with some personal stuff and didnt have time to look into this.
Meantime as this was urgent, I had already done the fix and didnt have time to look into forums.
My code is:
Code:
string NormaliseNumber(string & sDialled)
{
string sNormalised;
if (sDialled.empty() == false)
{
if (sDialled.at(0) == '+')
sNormalised = sDialled;
else
{
unsigned int nCodeLen = m_sIntAccessCode.size();
if (nCodeLen > 0 && sDialled.size() >= nCodeLen && sDialled.substr(0, nCodeLen) == m_sIntAccessCode)
sNormalised = "+" + sDialled.substr(nCodeLen);
else
{
nCodeLen = m_sTrunkAccessCode.size();
if (nCodeLen > 0 && sDialled.size() >= nCodeLen && sDialled.substr(0, nCodeLen) == m_sTrunkAccessCode)
sNormalised = "+" + m_sCountryCode + sDialled.substr(nCodeLen);
else if(m_bNoTrunkAccessCode)
{
// American networks do not have trunk access code
// Still we need to normalise it by adding the normal trunk access code
// Which is usually numbers beginning with "0"
string sNewDialled;
string sRcvdCountryCode = sDialled.substr(0, m_sCountryCode.size());
if( !sRcvdCountryCode.compare(m_sCountryCode) )
{
// For numbers in format 1<MSN>
sNewDialled = m_sTrunkAccessCode + sDialled.substr(m_sCountryCode.size());
}
else
{
// For numbers in format <MSN>
sNewDialled = m_sTrunkAccessCode + sDialled;
}
if (nCodeLen > 0 && sNewDialled.size() >= nCodeLen && sNewDialled.substr(0, nCodeLen) == m_sTrunkAccessCode)
sNormalised = "+" + m_sCountryCode + sNewDialled.substr(nCodeLen);
}
else
{
sNormalised = sDialled;
}
}
}
}
return sNormalised;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|