If string::length is returning 0 then there's nothing in it, so it is correct that the loop doesn't run. It does sound like something is going wrong with your string population code, and that the str_len value is getting out of step with the string's actual length.
You
must eliminate the str_len parameters from your functions, e.g. use
Phonetic(const wstring& wstrInput)
rather than
Phonetic(const wstring& wstrInput, int str_len)
as it's
dangerous -- you cannot say that a string has length str_len when in fact it has some other length.
string and all the standard constainers (vector, etc) know their own size (or length, in string's case.) You should not try and keep track of the size/length separately as it introduces the possibility that the length gets out of step with the actual size/length, as you have found out!
As an interim measure, so you don't have to chase the changes all the way though your code in one go, you could:
1. just ignore the parameter (do a search and replace: ", int str_len" -> ", int /*str_len*/ -- or similar, where I'm assuming you're naming is consistent.) This will break all functions which are erroneously using the str_len parameter so you can fix them.
2. add local str_len variables where required. e.g. change
1 2
|
vector<wstring> Parser::Phonetic(const wstring& wstrInput, int str_len)
{
|
to
1 2 3
|
vector<wstring> Parser::Phonetic(const wstring& wstrInput, int /*str_len*/)
{
const int str_len = wstrInput.length();
|
So you don't have to alter the functions either (save for the new variable.)
Then you can alter the function signatures and tidy up the function code in a more leisurely fashion.
But if a wstring doesn't hold chars, |
It does hold characters, or chars in the looser sense, but not chars in the sense of the C++
char
data type.
In the Windows world, a
wstring
holds 16-bit
wchar_t
characters, rather than the 8-bit
char
characters which
string
uses. (wchar_t can be other sizes, e.g. x86 Linux uses a 32-bit wchar_t)
Andy