| 611 | ////////////////////////////////////////////////////////////////////////////// |
| 612 | |
| 613 | void cEncoder::Encode(TSTRING& strIn) const |
| 614 | { |
| 615 | // TODO:BAM -- reserve space for strOut as an optimization? |
| 616 | TSTRING strOut; // encoded string we will build up |
| 617 | |
| 618 | TSTRING::const_iterator cur = strIn.begin(); // pointer to working position in strIn |
| 619 | const TSTRING::const_iterator end = strIn.end(); // end of strIn |
| 620 | TSTRING::const_iterator first = end; // identifies beginning of current character |
| 621 | TSTRING::const_iterator last = end; // identifies end of current character |
| 622 | |
| 623 | // while get next char (updates cur) |
| 624 | while (cCharUtil::PopNextChar(cur, end, first, last)) |
| 625 | { |
| 626 | bool fCharEncoded = false; // answers: did char need encoding? |
| 627 | sack_type::const_iterator atE; |
| 628 | |
| 629 | // for all encoders |
| 630 | for (atE = m_encodings.begin(); atE != m_encodings.end(); atE++) |
| 631 | { |
| 632 | // does char need encoding? |
| 633 | if ((*atE)->NeedsEncoding(first, last)) |
| 634 | { |
| 635 | strOut += Encode(first, last, atE); |
| 636 | fCharEncoded = true; |
| 637 | break; // each char should only fail at most one |
| 638 | // encoding test, so it should be cool to quit |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | if (!fCharEncoded) |
| 643 | { |
| 644 | strOut.append(first, last); // simply add current char to output since it needed no encoding |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | // pass back encoded string |
| 649 | strIn = strOut; |
| 650 | } |
| 651 | |
| 652 | TSTRING |
| 653 | cEncoder::Encode(TSTRING::const_iterator first, TSTRING::const_iterator last, sack_type::const_iterator encoding) const |
no test coverage detected