| 24 | |
| 25 | |
| 26 | Widget::Widget(std::shared_ptr<Widget> parent, const ElementPtr &element) { |
| 27 | this->_parent = std::move(parent); |
| 28 | this->initFormElement(element); |
| 29 | // remove digits or blank space in string |
| 30 | auto removeIterator = this->_text.erase( |
| 31 | std::remove_if(this->_text.begin(), this->_text.end(), ifCharIsDigitOrBlank), |
| 32 | this->_text.end()); |
| 33 | this->_text = std::string(this->_text.begin(), removeIterator); |
| 34 | if (STATE_WITH_TEXT || Preference::inst()->isForceUseTextModel()) { |
| 35 | bool overMaxLen = this->_text.size() > STATE_TEXT_MAX_LEN; |
| 36 | this->_text = this->_text.substr(0, STATE_TEXT_MAX_LEN * 4); |
| 37 | int cutLength = STATE_TEXT_MAX_LEN; |
| 38 | if (this->_text.length() > cutLength && isZhCn(this->_text[STATE_TEXT_MAX_LEN])) { |
| 39 | int ci = 0; |
| 40 | for (; ci < cutLength; ci++) { |
| 41 | if (isZhCn(this->_text[ci])) { |
| 42 | ci += 2; |
| 43 | } |
| 44 | } |
| 45 | cutLength = ci; |
| 46 | } |
| 47 | |
| 48 | this->_text = this->_text.substr(0, cutLength); |
| 49 | if (!overMaxLen) |
| 50 | this->_hashcode ^= (0x79b9 + (std::hash<std::string>{}(this->_text) << 5)); |
| 51 | } |
| 52 | |
| 53 | if (STATE_WITH_INDEX) { |
| 54 | this->_hashcode ^= ((0x79b9 + (std::hash<int>{}(this->_index) << 6)) << 1); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void Widget::initFormElement(const ElementPtr &element) { |
| 59 | if (element->getCheckable()) |
nothing calls this directly
no test coverage detected