list
ASCIIコードと対応する数値のグローバルベクトルと、のような文字列が与えられた場合000.00-000.0.0.0
、この関数はinput
2文字または3文字の長さのトークン文字列を受け取り、0〜184の数値を表す単一のASCII記号に置き換えます。デリミネータなしの短縮文字列を。として返しますout
。また、逆(方向1)では、ASCII記号を指定すると、数値文字列に変換して戻ります。
//looks for input string in vector and returns output, 'c' is check row, 'r' is return row
string vectorSearch(string &check, int n, int c, int r)
{
if (check.length() <= 1)
return check;
if (list[n][c] == check || list[n][c] == ('0'+check)) //adds leading zero if 2char long
return list[n][r];
else
return vectorSearch (check, ++n, c, r);
}
//this function takes an ontology and either changes from single char
//to string or takes strings and converts to char representation
string Lexicon::convertOntology(string input, int direction, string out, string temp)
{
if (input == "" && temp == "")
return out; //check for completed conversion
else {
if (input[0] == '.' || input[0] == '-' || input == "") { //found deliniator or endk
if (input != "") return convertOntology(input.substr(1),direction,
out+=vectorSearch(temp, 0, direction, 1-direction), "");
else return convertOntology("", direction,
out+=vectorSearch(temp, 0, direction, 1-direction), "");
} else
return convertOntology(input.substr(1), direction, out, temp+=input[0]); //increment and check
}
}
これらの関数は、最後の文字が解析された後の出力を除いて、正常に機能します。行にブレークがあるとreturn convertOntology(input.substr(1), direction, out+=add, temp);
、エラーが発生します。最後のパススルーで一時をクリアし、一時文字を出力文字列に追加する必要があります。一時は== 1文字であるため、そのまま返される必要があります。次に、とのリターンチェックをクリアします。しかし、それはの最初の行で途切れることは決してなく、input == ""
temp == "0"
vectorSearch()
vectorSearch()
convertOntology()
input
temp == ""
vectorSearch()
Unhandled exception at 0x77bc15de exception: std::out_of_range at memory location 0x0035cf1c
何が起こっている?これは、リターンを介した再帰バックトラックの問題であり、再帰ループを中断するためのリターンがどこかにありませんか?