Changeset View
Changeset View
Standalone View
Standalone View
core/textpage.cpp
Show First 20 Lines • Show All 840 Lines • ▼ Show 20 Line(s) | |||||
841 | 841 | | |||
842 | RegularAreaRect* TextPagePrivate::findTextInternalForward( int searchID, const QString &_query, | 842 | RegularAreaRect* TextPagePrivate::findTextInternalForward( int searchID, const QString &_query, | ||
843 | TextComparisonFunction comparer, | 843 | TextComparisonFunction comparer, | ||
844 | const TextList::ConstIterator &start, | 844 | const TextList::ConstIterator &start, | ||
845 | int start_offset, | 845 | int start_offset, | ||
846 | const TextList::ConstIterator &end) | 846 | const TextList::ConstIterator &end) | ||
847 | { | 847 | { | ||
848 | // normalize query search all unicode (including glyphs) | 848 | // normalize query search all unicode (including glyphs) | ||
849 | const QString query = _query.normalized(QString::NormalizationForm_KC); | 849 | const QString query = _query.normalized(QString::NormalizationForm_KC).replace(QRegExp("[\\s\n\r]+"), QString(' ')); | ||
850 | 850 | | |||
851 | // j is the current position in our query | 851 | // j is the current position in our query | ||
852 | // len is the length of the string in TextEntity | 852 | // len is the length of the string in TextEntity | ||
853 | // queryLeft is the length of the query we have left | 853 | // queryLeft is the length of the query we have left | ||
854 | int j=0, queryLeft=query.length(); | 854 | int j=0, queryLeft=query.length(); | ||
855 | 855 | | |||
856 | TextList::ConstIterator it = start; | 856 | TextList::ConstIterator it = start; | ||
857 | int offset = start_offset; | 857 | int offset = start_offset; | ||
858 | 858 | | |||
859 | TextList::ConstIterator it_begin = TextList::ConstIterator(); | 859 | TextList::ConstIterator it_begin = TextList::ConstIterator(); | ||
860 | int offset_begin = 0; //dummy initial value to suppress compiler warnings | 860 | int offset_begin = 0; //dummy initial value to suppress compiler warnings | ||
861 | 861 | | |||
862 | while ( it != end ) | 862 | while ( it != end ) | ||
863 | { | 863 | { | ||
864 | const TinyTextEntity* curEntity = *it; | 864 | const TinyTextEntity* curEntity = *it; | ||
865 | const QString& str = curEntity->text(); | 865 | const QString& origStr = curEntity->text(); | ||
866 | int len = stringLengthAdaptedWithHyphen(str, it, m_words.constEnd()); | 866 | const int len = stringLengthAdaptedWithHyphen(origStr, it, m_words.constEnd()); | ||
aacid: given that you're modifying this line, make len const :)
Also are you totally sure this needs… | |||||
I need it to be strNotUsed because I'm making str const, and I'm replacing the '\n' as soon as I create it. It would mess up the stringLenghtAdaptedWithHyphen because it would have the "-\n" text entities as " " joaonetto: I need it to be strNotUsed because I'm making str const, and I'm replacing the '\n' as soon as… | |||||
867 | const QString str = QString(origStr).replace(QRegExp("[\\s\n\r]+"), QString(' ')); | ||||
aacid: const | |||||
strNotUsed seems like a weird variable name given you actually use it the two following names. Would something like origStr or something make more sense? aacid: strNotUsed seems like a weird variable name given you actually use it the two following names. | |||||
Yes, I will make it origStr, it is better. Unfortunately curEntity->text() needs a const variable. I would put it in str, but it would mess up the stringLenghtAdaptedWithHyphen. joaonetto: Yes, I will make it origStr, it is better.
Unfortunately curEntity->text() needs a const… | |||||
867 | 868 | | |||
868 | if (offset >= len) | 869 | if (offset >= len) | ||
869 | { | 870 | { | ||
870 | it++; | 871 | it++; | ||
871 | offset = 0; | 872 | offset = 0; | ||
872 | continue; | 873 | continue; | ||
873 | } | 874 | } | ||
874 | 875 | | |||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | |||||
950 | 951 | | |||
951 | RegularAreaRect* TextPagePrivate::findTextInternalBackward( int searchID, const QString &_query, | 952 | RegularAreaRect* TextPagePrivate::findTextInternalBackward( int searchID, const QString &_query, | ||
952 | TextComparisonFunction comparer, | 953 | TextComparisonFunction comparer, | ||
953 | const TextList::ConstIterator &start, | 954 | const TextList::ConstIterator &start, | ||
954 | int start_offset, | 955 | int start_offset, | ||
955 | const TextList::ConstIterator &end) | 956 | const TextList::ConstIterator &end) | ||
956 | { | 957 | { | ||
957 | // normalize query to search all unicode (including glyphs) | 958 | // normalize query to search all unicode (including glyphs) | ||
958 | const QString query = _query.normalized(QString::NormalizationForm_KC); | 959 | const QString query = _query.normalized(QString::NormalizationForm_KC).replace(QRegExp("[\\s\n\r]+"), QString(' ')); | ||
959 | 960 | | |||
960 | // j is the current position in our query | 961 | // j is the current position in our query | ||
961 | // len is the length of the string in TextEntity | 962 | // len is the length of the string in TextEntity | ||
962 | // queryLeft is the length of the query we have left | 963 | // queryLeft is the length of the query we have left | ||
963 | int j=query.length(), queryLeft=query.length(); | 964 | int j=query.length(), queryLeft=query.length(); | ||
964 | 965 | | |||
965 | TextList::ConstIterator it = start; | 966 | TextList::ConstIterator it = start; | ||
966 | int offset = start_offset; | 967 | int offset = start_offset; | ||
967 | 968 | | |||
968 | TextList::ConstIterator it_begin = TextList::ConstIterator(); | 969 | TextList::ConstIterator it_begin = TextList::ConstIterator(); | ||
969 | int offset_begin = 0; //dummy initial value to suppress compiler warnings | 970 | int offset_begin = 0; //dummy initial value to suppress compiler warnings | ||
970 | 971 | | |||
971 | while ( true ) | 972 | while ( true ) | ||
972 | { | 973 | { | ||
973 | if (offset <= 0) | 974 | if (offset <= 0) | ||
974 | { | 975 | { | ||
975 | if ( it == end ) | 976 | if ( it == end ) | ||
976 | { | 977 | { | ||
977 | break; | 978 | break; | ||
978 | } | 979 | } | ||
979 | it--; | 980 | it--; | ||
980 | } | 981 | } | ||
981 | 982 | | |||
982 | const TinyTextEntity* curEntity = *it; | 983 | const TinyTextEntity* curEntity = *it; | ||
983 | const QString& str = curEntity->text(); | 984 | const QString& origStr = curEntity->text(); | ||
984 | int len = stringLengthAdaptedWithHyphen(str, it, m_words.constEnd()); | 985 | const int len = stringLengthAdaptedWithHyphen(origStr, it, m_words.constEnd()); | ||
986 | const QString str = QString(origStr).replace(QRegExp("[\\s\n\r]+"), QString(' ')); | ||||
aacid: const | |||||
985 | 987 | | |||
986 | if (offset <= 0) | 988 | if (offset <= 0) | ||
987 | { | 989 | { | ||
988 | offset = len; | 990 | offset = len; | ||
989 | } | 991 | } | ||
990 | 992 | | |||
991 | if ( it_begin == TextList::ConstIterator() ) | 993 | if ( it_begin == TextList::ConstIterator() ) | ||
992 | { | 994 | { | ||
▲ Show 20 Lines • Show All 1046 Lines • Show Last 20 Lines |
given that you're modifying this line, make len const :)
Also are you totally sure this needs to be over strNotUsed and not str? Hmmm i guess it works both ways since str is the same length as strNotUsed