1. template<typename Ch> unsignedint rtoi(const basic_string<Ch>& romanStr) {
2. int result = 0; /* value to return */
3. AdditiveTerm currentTerm;
4.
5. unsignedint repeatedTimes;
6.
7. Ch lastSymbol = L'\0', currentSymbol, nextSymbol;
8.
9. /* main computing loop: inside reasonable length and without reaching the
10. end of the null terminated string */
11. for (typename basic_string<Ch>::const_iterator iter = romanStr.begin(),
12. iterNext;
13. iter!=romanStr.end();
14. iter+= currentTerm.size,
15. result+= currentTerm.value) {
16. currentSymbol = *iter;
17.
18. /* Rule 1: Repetition. Can't happen more than three times and not every
19. symbol is repeatable */
20. if (lastSymbol==currentSymbol) {
21. if ((++repeatedTimes==4)||(isNotRepeatable(currentSymbol))) {
22. throw ConversionError(IllegalRepetition);
23. }
24. } else {
25. repeatedTimes = 1;
26. lastSymbol = currentSymbol;
27. }
28.
29. /* the current symbol plus its follower (if not at the end) are
30. evaluated in getNexAdditive() to see how much to cumulate*/
31. nextSymbol = ((iterNext = iter+1)==romanStr.end()) ? L'0' : *(iterNext);
32. currentTerm = getNextTerm(currentSymbol, nextSymbol);
33. }
34.
35. return result;
36. }
But I do not know how to analyze the line 31 nextSymbol = ((iterNext = iter+1)==romanStr.end()) ? L'0' : *(iterNext); Thanks.
Because there's an old way and a new way. Technically in this case both are about the same age. The operator handles simple if else statements where if else can expand to handle more than once case.
the ?: is usually used during expressions and is nice and quick.