summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/keyz-cfg/zkb.cpp716
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp15
-rw-r--r--noncore/apps/opie-reader/BuffDoc.h116
-rw-r--r--noncore/apps/opie-reader/CEncoding.h16
-rw-r--r--noncore/apps/opie-reader/CExpander.h140
-rw-r--r--noncore/apps/opie-reader/Filedata.h56
-rw-r--r--noncore/apps/opie-reader/FontControl.h178
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp125
-rw-r--r--noncore/apps/opie-reader/QTReader.h124
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.h112
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.h14
-rw-r--r--noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp2282
12 files changed, 1957 insertions, 1937 deletions
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp
index 58bde2a..c9e1dc5 100644
--- a/noncore/apps/keyz-cfg/zkb.cpp
+++ b/noncore/apps/keyz-cfg/zkb.cpp
@@ -1,589 +1,589 @@
#include "zkb.h"
+
+/* OPIE */
+#include <opie2/odebug.h>
+
#include <stdio.h>
// Implementation of Action class
Action::Action():state(0), keycode(0), unicode(0), flags(0) {
}
Action::Action(State* s, ushort kc, ushort uni, int f):
- state(s), keycode(kc), unicode(uni), flags(f) {
+ state(s), keycode(kc), unicode(uni), flags(f) {
}
Action::~Action() {
}
State* Action::getState() const {
- return state;
+ return state;
}
void Action::setState(State* s) {
- state = s;
- setDefined(true);
+ state = s;
+ setDefined(true);
}
bool Action::hasEvent() const {
- return flags & Event;
+ return flags & Event;
}
void Action::setEvent(bool e) {
- flags = (flags & ~Event) | ((e) ? Event : 0);
+ flags = (flags & ~Event) | ((e) ? Event : 0);
- if (e) {
- setDefined(true);
- } else {
- if (state == 0) {
- setDefined(false);
- }
- }
+ if (e) {
+ setDefined(true);
+ } else {
+ if (state == 0) {
+ setDefined(false);
+ }
+ }
}
bool Action::isDefined() const {
- return flags & Defined;
+ return flags & Defined;
}
void Action::setDefined(bool d) {
- flags = (flags & ~Defined) | ((d) ? Defined : 0);
+ flags = (flags & ~Defined) | ((d) ? Defined : 0);
}
int Action::getKeycode() const {
- return keycode;
+ return keycode;
}
void Action::setKeycode(int c) {
- keycode = (ushort) c;
- setEvent(true);
+ keycode = (ushort) c;
+ setEvent(true);
}
int Action::getUnicode() const {
- return unicode;
+ return unicode;
}
void Action::setUnicode(int u) {
- unicode = (ushort) u;
- setEvent(true);
+ unicode = (ushort) u;
+ setEvent(true);
}
int Action::getModifiers() const {
- int ret = 0;
- if (flags & Shift_Mod) {
- ret |= Qt::ShiftButton;
- }
+ int ret = 0;
+ if (flags & Shift_Mod) {
+ ret |= Qt::ShiftButton;
+ }
- if (flags & Ctrl_Mod) {
- ret |= Qt::ControlButton;
- }
+ if (flags & Ctrl_Mod) {
+ ret |= Qt::ControlButton;
+ }
- if (flags & Alt_Mod) {
- ret |= Qt::AltButton;
- }
+ if (flags & Alt_Mod) {
+ ret |= Qt::AltButton;
+ }
- if (flags & Keypad_Mod) {
- ret |= Qt::Keypad;
- }
+ if (flags & Keypad_Mod) {
+ ret |= Qt::Keypad;
+ }
- return ret;
+ return ret;
}
void Action::setModifiers(int m) {
- int n = 0;
+ int n = 0;
- if (m & Qt::ShiftButton) {
- n |= Shift_Mod;
- }
+ if (m & Qt::ShiftButton) {
+ n |= Shift_Mod;
+ }
- if (m & Qt::ControlButton) {
- n |= Ctrl_Mod;
- }
+ if (m & Qt::ControlButton) {
+ n |= Ctrl_Mod;
+ }
- if (m & Qt::AltButton) {
- n |= Alt_Mod;
- }
+ if (m & Qt::AltButton) {
+ n |= Alt_Mod;
+ }
- if (m & Qt::Keypad) {
- n |= Keypad_Mod;
- }
+ if (m & Qt::Keypad) {
+ n |= Keypad_Mod;
+ }
- flags = flags & ~Mod_Bits | n;
- setEvent(true);
+ flags = flags & ~Mod_Bits | n;
+ setEvent(true);
}
bool Action::isPressed() const {
- return (flags & Press) != 0;
+ return (flags & Press) != 0;
}
void Action::setPressed(bool p) {
- flags = (flags & ~Press) | ((p) ? Press : 0);
- setEvent(true);
+ flags = (flags & ~Press) | ((p) ? Press : 0);
+ setEvent(true);
}
bool Action::isAutorepeat() const {
- return (flags & Autorepeat) != 0;
+ return (flags & Autorepeat) != 0;
}
void Action::setAutorepeat(bool p) {
- flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0);
- setEvent(true);
+ flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0);
+ setEvent(true);
}
// Implementation of State class
const short State::x1[] = { /* from 0x20 to 0x5f */
- 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */
- 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */
- 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */
- 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */
- 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */
- 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */
- 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */
- 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */
- 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */
- -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */
+ 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */
+ 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */
+ 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */
+ 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */
+ 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */
+ 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */
+ 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */
+ 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */
+ 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */
+ -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */
};
const short State::x2[] = { /* from 0x1000 to 0x1057*/
- 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */
- -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */
- 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */
- 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */
- -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */
- -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */
- 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */
+ 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */
+ -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */
+ 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */
+ 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */
+ -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */
+ -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */
+ 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */
};
-
+
State::State(State* p):parent(p), keys(0) {
- keys = new Action[Key_Max * 2 + 1];
+ keys = new Action[Key_Max * 2 + 1];
}
State::State(const State& s) {
- parent = s.parent;
- keys = new Action[Key_Max * 2 + 1];
- memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
+ parent = s.parent;
+ keys = new Action[Key_Max * 2 + 1];
+ memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
}
State::~State() {
- if (keys!=0) {
- delete [] keys;
- }
+ if (keys!=0) {
+ delete [] keys;
+ }
}
Action* State::get(int keycode, bool pressed, bool follow) const {
- Action* ret = 0;
- int n = translateKeycode(keycode);
+ Action* ret = 0;
+ int n = translateKeycode(keycode);
- if (n != -1 && keys != 0) {
- if (pressed) {
- n += Key_Max;
- }
- ret = &keys[n];
- }
+ if (n != -1 && keys != 0) {
+ if (pressed) {
+ n += Key_Max;
+ }
+ ret = &keys[n];
+ }
- if (ret==0 || !ret->isDefined()) {
- if (follow && parent!=0) {
- ret = parent->get(keycode, pressed, follow);
- }
- }
+ if (ret==0 || !ret->isDefined()) {
+ if (follow && parent!=0) {
+ ret = parent->get(keycode, pressed, follow);
+ }
+ }
- return ret;
+ return ret;
}
bool State::set(int keycode, bool pressed, Action& action) {
- int n = translateKeycode(keycode);
+ int n = translateKeycode(keycode);
- if (n==-1 || keys==0) {
- return false;
- }
+ if (n==-1 || keys==0) {
+ return false;
+ }
- if (pressed) {
- n += Key_Max + 1;
- }
+ if (pressed) {
+ n += Key_Max + 1;
+ }
- keys[n] = action;
- return true;
+ keys[n] = action;
+ return true;
}
State* State::getParent() const {
- return parent;
+ return parent;
}
void State::setParent(State* s) {
- parent = s;
+ parent = s;
}
int State::translateKeycode(int keycode) const {
- if (keycode < 0x20) {
- return -1;
- }
+ if (keycode < 0x20) {
+ return -1;
+ }
- if (keycode < 0x80) {
- return x1[keycode - 0x20];
- }
+ if (keycode < 0x80) {
+ return x1[keycode - 0x20];
+ }
- if (keycode < 0x1000) {
- return -1;
- }
+ if (keycode < 0x1000) {
+ return -1;
+ }
- if (keycode < 0x1057) {
- return x2[keycode - 0x1000];
- }
+ if (keycode < 0x1057) {
+ return x2[keycode - 0x1000];
+ }
- return -1;
+ return -1;
}
// Implementation of Keymap class
Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
- repeatDelay=400;
- repeatPeriod=80;
- connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
+ repeatDelay=400;
+ repeatPeriod=80;
+ connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
}
Keymap::~Keymap() {
- QMap<QString, State*>::Iterator it;
- for(it = states.begin(); it != states.end(); ++it) {
- delete it.data();
- }
- states.clear();
+ QMap<QString, State*>::Iterator it;
+ for(it = states.begin(); it != states.end(); ++it) {
+ delete it.data();
+ }
+ states.clear();
}
bool Keymap::filter(int unicode, int keycode, int modifiers,
- bool isPress, bool autoRepeat) {
+ bool isPress, bool autoRepeat) {
- qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, "
- "ispressed=%x\n", unicode, keycode, modifiers, isPress);
+ odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
+ << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
- if (!enabled) {
- return false;
- }
+ if (!enabled) {
+ return false;
+ }
- // the second check is workaround to make suspend work if
- // the user pressed it right after he did resume. for some
- // reason the event sent by qt has autoRepeat true in this
- // case
- if (autoRepeat && keycode != 4177) {
- return true;
- }
+ // the second check is workaround to make suspend work if
+ // the user pressed it right after he did resume. for some
+ // reason the event sent by qt has autoRepeat true in this
+ // case
+ if (autoRepeat && keycode != 4177) {
+ return true;
+ }
- (void) unicode; (void) modifiers;
+ (void) unicode; (void) modifiers;
- Action* action = currentState->get(keycode, isPress, true);
- if (action==0 || !action->isDefined()) {
- return true;
- }
+ Action* action = currentState->get(keycode, isPress, true);
+ if (action==0 || !action->isDefined()) {
+ return true;
+ }
- if (action->hasEvent()) {
- qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, "
- "ispressed=%x\n", action->getUnicode(),
- action->getKeycode(), action->getModifiers(),
- action->isPressed());
+ if (action->hasEvent()) {
+ odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode()
+ << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl;
- QWSServer::sendKeyEvent(action->getUnicode(),
- action->getKeycode(), action->getModifiers(),
- action->isPressed(), false);
- }
+ QWSServer::sendKeyEvent(action->getUnicode(),
+ action->getKeycode(), action->getModifiers(),
+ action->isPressed(), false);
+ }
- if (action->isAutorepeat()) {
- autoRepeatAction = action;
- repeater.start(repeatDelay, TRUE);
- } else {
- autoRepeatAction = 0;
- }
+ if (action->isAutorepeat()) {
+ autoRepeatAction = action;
+ repeater.start(repeatDelay, TRUE);
+ } else {
+ autoRepeatAction = 0;
+ }
- State* nstate = action->getState();
- if (nstate != 0) {
- setCurrentState(nstate);
- QString lbl = getCurrentLabel();
- if (!lbl.isEmpty()) {
- emit stateChanged(lbl);
- }
- }
+ State* nstate = action->getState();
+ if (nstate != 0) {
+ setCurrentState(nstate);
+ QString lbl = getCurrentLabel();
+ if (!lbl.isEmpty()) {
+ emit stateChanged(lbl);
+ }
+ }
- return true;
+ return true;
}
void Keymap::enable() {
- enabled = true;
+ enabled = true;
}
void Keymap::disable() {
- enabled = false;
+ enabled = false;
}
QStringList Keymap::listStates() {
- QStringList ret;
+ QStringList ret;
- QMap<QString, State*>::Iterator it;
- for(it = states.begin(); it != states.end(); ++it) {
- ret.append(it.key());
- }
+ QMap<QString, State*>::Iterator it;
+ for(it = states.begin(); it != states.end(); ++it) {
+ ret.append(it.key());
+ }
- return ret;
+ return ret;
}
State* Keymap::getStateByName(const QString& name) {
- QMap<QString, State*>::Iterator it = states.find(name);
+ QMap<QString, State*>::Iterator it = states.find(name);
- if (it == states.end()) {
- return 0;
- }
+ if (it == states.end()) {
+ return 0;
+ }
- return it.data();
+ return it.data();
}
QStringList Keymap::listLabels() {
- QStringList ret;
+ QStringList ret;
- for(uint i = 0; i < labelList.count(); i++) {
- ret.append(*labelList.at(i));
- }
+ for(uint i = 0; i < labelList.count(); i++) {
+ ret.append(*labelList.at(i));
+ }
- return ret;
+ return ret;
}
State* Keymap::getStateByLabel(const QString& label) {
- QMap<QString, QString>::Iterator lit = labels.find(label);
- State* state = 0;
+ QMap<QString, QString>::Iterator lit = labels.find(label);
+ State* state = 0;
- if (lit == labels.end()) {
- return 0;
- }
+ if (lit == labels.end()) {
+ return 0;
+ }
- QString name = lit.data();
+ QString name = lit.data();
- int n = name.find(":*");
- if (n>=0 && n==(int)(name.length()-2)) {
- name=name.left(name.length() - 1);
+ int n = name.find(":*");
+ if (n>=0 && n==(int)(name.length()-2)) {
+ name=name.left(name.length() - 1);
- n = currentStateName.findRev(":");
- if (n >= 0) {
- name += currentStateName.mid(n+1);
- }
- }
+ n = currentStateName.findRev(":");
+ if (n >= 0) {
+ name += currentStateName.mid(n+1);
+ }
+ }
-// odebug << "look for: " << name.utf8() << "\n" << oendl;
- QMap<QString, State*>::Iterator sit = states.find(name);
- if (sit != states.end()) {
- state = sit.data();
- }
+// odebug << "look for: " << name.utf8() << "\n" << oendl;
+ QMap<QString, State*>::Iterator sit = states.find(name);
+ if (sit != states.end()) {
+ state = sit.data();
+ }
- return state;
+ return state;
}
bool Keymap::addState(const QString& name, State* state) {
- if (states.find(name) != states.end()) {
- return false;
- }
+ if (states.find(name) != states.end()) {
+ return false;
+ }
- states.insert(name, state);
- lsmapInSync = false;
+ states.insert(name, state);
+ lsmapInSync = false;
- if (currentState == 0) {
- setCurrentState(state);
- }
+ if (currentState == 0) {
+ setCurrentState(state);
+ }
- return true;
+ return true;
}
State* Keymap::getCurrentState() const {
- return currentState;
+ return currentState;
}
QString Keymap::getCurrentLabel() {
- return currentLabel;
+ return currentLabel;
}
bool Keymap::setCurrentState(State* state) {
- QMap<QString, State*>::Iterator it;
- for(it = states.begin(); it != states.end(); ++it) {
- State* s = it.data();
- if (s == state) {
- currentState = s;
- currentStateName = it.key();
+ QMap<QString, State*>::Iterator it;
+ for(it = states.begin(); it != states.end(); ++it) {
+ State* s = it.data();
+ if (s == state) {
+ currentState = s;
+ currentStateName = it.key();
- qDebug("state changed: %s\n", (const char*)
- currentStateName.utf8());
+ odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl;
- if (!lsmapInSync) {
- generateLabelStateMaps();
- }
+ if (!lsmapInSync) {
+ generateLabelStateMaps();
+ }
- QMap<State*, QString>::Iterator tit;
- tit = stateLabelMap.find(state);
- if (tit != stateLabelMap.end()) {
- currentLabel = tit.data();
- } else {
-// odebug << "no label for: " + currentStateName + "\n" << oendl;
- currentLabel = "";
- }
+ QMap<State*, QString>::Iterator tit;
+ tit = stateLabelMap.find(state);
+ if (tit != stateLabelMap.end()) {
+ currentLabel = tit.data();
+ } else {
+// odebug << "no label for: " + currentStateName + "\n" << oendl;
+ currentLabel = "";
+ }
- return true;
- }
- }
+ return true;
+ }
+ }
- return false;
+ return false;
}
bool Keymap::removeState(const QString& name, bool force) {
- QMap<QString, State*>::Iterator it = states.find(name);
+ QMap<QString, State*>::Iterator it = states.find(name);
- if (it == states.end()) {
- return false;
- }
+ if (it == states.end()) {
+ return false;
+ }
- State* state = it.data();
- QList<Action> acts = findStateUsage(state);
+ State* state = it.data();
+ QList<Action> acts = findStateUsage(state);
- if (!acts.isEmpty()) {
- if (!force) {
- return false;
- } else {
- for(Action* a = acts.first(); a != 0; a = acts.next()) {
- a->setState(0);
- }
- }
- }
+ if (!acts.isEmpty()) {
+ if (!force) {
+ return false;
+ } else {
+ for(Action* a = acts.first(); a != 0; a = acts.next()) {
+ a->setState(0);
+ }
+ }
+ }
- if (state == currentState) {
- if (states.begin() != states.end()) {
- setCurrentState(states.begin().data());
- }
- }
+ if (state == currentState) {
+ if (states.begin() != states.end()) {
+ setCurrentState(states.begin().data());
+ }
+ }
- states.remove(it);
- delete state;
+ states.remove(it);
+ delete state;
- lsmapInSync = false;
+ lsmapInSync = false;
- return true;
+ return true;
}
void Keymap::autoRepeat() {
- if (autoRepeatAction != 0) {
- qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, "
- "ispressed=%x\n", autoRepeatAction->getUnicode(),
- autoRepeatAction->getKeycode(),
- autoRepeatAction->getModifiers(),
- autoRepeatAction->isPressed());
+ if (autoRepeatAction != 0) {
+ odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode()
+ << ", keycode=" << autoRepeatAction->getKeycode()
+ << ", modifiers=" << autoRepeatAction->getModifiers()
+ << "ispressed=" << autoRepeatAction->isPressed() << oendl;
- QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(),
- autoRepeatAction->getKeycode(),
- autoRepeatAction->getModifiers(),
- autoRepeatAction->isPressed(), true);
- }
+ QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(),
+ autoRepeatAction->getKeycode(),
+ autoRepeatAction->getModifiers(),
+ autoRepeatAction->isPressed(), true);
+ }
- repeater.start(repeatPeriod, TRUE);
+ repeater.start(repeatPeriod, TRUE);
}
bool Keymap::addLabel(const QString& label, const QString& state, int index) {
- if (labels.find(label) != labels.end()) {
- return false;
- }
+ if (labels.find(label) != labels.end()) {
+ return false;
+ }
- labels.insert(label, state);
- const QString& l = labels.find(label).key();
- if (index == -1) {
- labelList.append(l);
- } else {
- labelList.insert(labelList.at(index), l);
- }
+ labels.insert(label, state);
+ const QString& l = labels.find(label).key();
+ if (index == -1) {
+ labelList.append(l);
+ } else {
+ labelList.insert(labelList.at(index), l);
+ }
- lsmapInSync = false;
+ lsmapInSync = false;
- return true;
+ return true;
}
bool Keymap::removeLabel(const QString& label) {
- if (labels.find(label) == labels.end()) {
- return false;
- }
+ if (labels.find(label) == labels.end()) {
+ return false;
+ }
- labels.remove(label);
- labelList.remove(label);
- lsmapInSync = false;
+ labels.remove(label);
+ labelList.remove(label);
+ lsmapInSync = false;
- if (label == currentLabel) {
- currentLabel = "";
- }
+ if (label == currentLabel) {
+ currentLabel = "";
+ }
- return true;
+ return true;
}
int Keymap::getAutorepeatDelay() const {
- return repeatDelay;
+ return repeatDelay;
}
void Keymap::setAutorepeatDelay(int n) {
- repeatDelay = n;
+ repeatDelay = n;
}
int Keymap::getAutorepeatPeriod() const {
- return repeatPeriod;
+ return repeatPeriod;
}
void Keymap::setAutorepeatPeriod(int n) {
- repeatPeriod = n;
+ repeatPeriod = n;
}
QList<Action> Keymap::findStateUsage(State* s) {
- QList<Action> ret;
+ QList<Action> ret;
- QMap<QString, State*>::Iterator it;
- for(it = states.begin(); it != states.end(); ++it) {
- State* state = it.data();
+ QMap<QString, State*>::Iterator it;
+ for(it = states.begin(); it != states.end(); ++it) {
+ State* state = it.data();
- for(int i = 0; i < 0x1100; i++) {
- Action* action = state->get(i, false);
- if (action!=0 && action->getState()==s) {
- ret.append(action);
- }
+ for(int i = 0; i < 0x1100; i++) {
+ Action* action = state->get(i, false);
+ if (action!=0 && action->getState()==s) {
+ ret.append(action);
+ }
- action = state->get(i, true);
- if (action!=0 && action->getState()==s) {
- ret.append(action);
- }
- }
- }
+ action = state->get(i, true);
+ if (action!=0 && action->getState()==s) {
+ ret.append(action);
+ }
+ }
+ }
- return ret;
+ return ret;
}
void Keymap::generateLabelStateMaps() {
- stateLabelMap.clear();
-
- QMap<QString, QString>::Iterator lit;
- for(lit = labels.begin(); lit != labels.end(); ++lit) {
- QString label = lit.key();
- QString name = lit.data();
-
- bool wc = false;
- int n = name.find("*");
- if (n>=0 && n==(int)(name.length()-1)) {
- name=name.left(name.length() - 1);
- wc = true;
- }
-
- QMap<QString, State*>::Iterator sit;
- for(sit = states.begin(); sit != states.end(); ++sit) {
- QString sname = sit.key();
- State* state = sit.data();
-
- if (sname.length() < name.length()) {
- continue;
- }
-
- if (sname.left(name.length()) == name) {
- if (wc || sname.length()==name.length()) {
- stateLabelMap.insert(state, label);
- }
-
- }
- }
- }
-
- lsmapInSync = true;
+ stateLabelMap.clear();
+
+ QMap<QString, QString>::Iterator lit;
+ for(lit = labels.begin(); lit != labels.end(); ++lit) {
+ QString label = lit.key();
+ QString name = lit.data();
+
+ bool wc = false;
+ int n = name.find("*");
+ if (n>=0 && n==(int)(name.length()-1)) {
+ name=name.left(name.length() - 1);
+ wc = true;
+ }
+
+ QMap<QString, State*>::Iterator sit;
+ for(sit = states.begin(); sit != states.end(); ++sit) {
+ QString sname = sit.key();
+ State* state = sit.data();
+
+ if (sname.length() < name.length()) {
+ continue;
+ }
+
+ if (sname.left(name.length()) == name) {
+ if (wc || sname.length()==name.length()) {
+ stateLabelMap.insert(state, label);
+ }
+
+ }
+ }
+ }
+
+ lsmapInSync = true;
}
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
index be2b897..f14080f 100644
--- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -376,132 +376,134 @@ void Gutenbrowser::downloadLibIndex() {
// { // use new, improved, *INSTANT* network-dialog-file-getterer
//// QMessageBox::message("Note","");
// }
// if(NetworkDlg)
// delete NetworkDlg;
}
void Gutenbrowser::PrintBtn() {
}
void Gutenbrowser::SearchBtn() {
if( loadCheck) {
odebug << "loadCheck: we have a loaded doc" << oendl;
Search();
}
// else
// QMessageBox::message("Note","Sorry, can't search. No etext is loaded");
}
void Gutenbrowser::ForwardBtn() {
if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) {
QString s;
QString insertString;
int pageSize= Lview->PageSize();
Lview->clear();
for(int fd=0; fd < pageSize - 1;fd++) {
f.readLine(s, 256);
if(useWrap)
s.replace(QRegExp("\n"),"");
insertString+=s;
Lview->insertLine( s, -1);
// odebug << s << oendl;
currentLine++;
}
// Lview->insertAt( insertString,0,0, FALSE);
currentFilePos = f.at();
// if( i_pageNum != pages) {
// Lview->MultiLine_Ex::pageDown( FALSE);
i_pageNum++;
pageStopArray.resize(i_pageNum + 1);
// int length = Lview->length();
pageStopArray[i_pageNum ] = currentFilePos;
- // qDebug("%d current page is number %d, pagesize %d, length %d, current %d",
- // currentFilePos, i_pageNum, pageSize, Lview->length(), pageStopArray[i_pageNum] );
+ // odebug << currentFilePos << " current page is number " << i_pageNum
+ // << ", pagesize " << pageSize << ", length " << Lview->length()
+ // << ", current " << pageStopArray[i_pageNum] << oendl;
setStatus();
Lview->setCursorPosition( 0, 0, FALSE);
// }
} else {
// odebug << "bal" << oendl;
// if( i_pageNum != pages) {
// // int newTop = Lview->Top();
// // if(Lview->lastRow() > i)
// Lview->ScrollUp(1);
// // i_pageNum++;
// setStatus();
// Lview->setCursorPosition( Lview->Top(), 0, FALSE);
// }
}
Lview->setFocus();
// odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl;
}
void Gutenbrowser::BackBtn() {
if( i_pageNum > 0) {
int pageSize= Lview->PageSize();
// int length=Lview->length();
i_pageNum--;
currentFilePos = f.at();
- // qDebug("%d move back to %d, current page number %d, %d, length %d",
- // currentFilePos, pageStopArray[i_pageNum - 1 ], i_pageNum, pageSize, Lview->length() );
+ // odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ]
+ // << ", current page number " << i_pageNum
+ // << ", " << pageSize << ", length " << Lview->length() << oendl;
if( i_pageNum < 2) {
f.at( 0);
} else {
if(!f.at( pageStopArray[i_pageNum - 1] ))
odebug << "File positioned backward did not work" << oendl;
}
QString s;
// int sizeLine=0;
Lview->clear();
// QString insertString;
for(int fd = 0; fd < pageSize ;fd++) {
// Lview->removeLine( Lview->PageSize() );
f.readLine(s, 256);
if(useWrap)
s.replace(QRegExp("\n"),"");
currentLine++;
// insertString+=s;
Lview->insertLine( s, -1);
}
// Lview->insertAt( insertString,0,0, FALSE);
if( !BackButton->autoRepeat() && !BackButton->isDown()) {
QString topR;
QString lastR;
QString pageR;
// int sizer = Lview->lastRow() - Lview->topRow();
// int i_topRow = Lview->topRow();
if( i_pageNum < 1)
i_pageNum = 1;
setCaption(QString::number(i_pageNum));
} else {
// int newTop = Lview->Top();
// if(Lview->lastRow() > i)
Lview->MultiLine_Ex::pageUp( FALSE);
// Lview->ScrollDown(1);
// i_pageNum--;
if( i_pageNum < 1)
i_pageNum = 1;
setStatus();
Lview->setCursorPosition( Lview->Top(), 0, FALSE);
}
}
Lview->setFocus();
}
@@ -754,98 +756,99 @@ bool Gutenbrowser::load( const char *fileName) {
Lview->setFixedVisibleLines(19);
else
Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2);
}
Config cfg("Gutenbrowser");
cfg.setGroup("General");
cfg.writeEntry("Current",fileName);
currentLine=0;
file_name=fileName;
QString o_file = fileName;
// if (i_pageNum < 1) {
i_pageNum = 1;
// }
odebug << "ready to open "+o_file << oendl;
if(f.isOpen()) f.close();
f.setName( o_file);
if ( !f.open( IO_ReadOnly)) {
QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) );
return false;
}
currentFilePos = 0;
pageStopArray.resize(3);
pageStopArray[0] = currentFilePos;
fileHandle = f.handle();
QString insertString;
QTextStream t(&f);
QString s;
for(int fd=0; fd < Lview->PageSize() ;fd++) {
s=t.readLine();
// insertString+=s;
if(useWrap)
s.replace(QRegExp("\n"),"");
// s.replace(QRegExp("\r"),"");
Lview->insertLine( s,-1);
currentLine++;
}
// int length = Lview->length();
currentFilePos = f.at();
pageStopArray[1] = currentFilePos;
- qDebug("<<<<<<<<<<<%d current page is number %d, length %d, current %d, pageSize %d",
- currentFilePos, i_pageNum, Lview->length(), pageStopArray[i_pageNum], Lview->PageSize() );
+ odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
+ << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
+ << ", pageSize " << Lview->PageSize() << oendl;
Lview->setMaxLines(Lview->PageSize()*2);
odebug << "Gulped " << currentLine << "" << oendl;
setCaption(title);
Lview->setAutoUpdate( TRUE);
Lview->setCursorPosition(0,0,FALSE);
// pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1;
//odebug << "number of pages " << pages << "" << oendl;
loadCheck = true;
enableButtons(true);
if( donateMenu->count() == 3) {
donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
}
Lview->setFocus();
// QCopEnvelope("QPE/System", "notBusy()" );
return true;
} // end load
void Gutenbrowser::Search() {
// if( searchDlg->isHidden())
{
odebug << "Starting search dialog" << oendl;
searchDlg = new SearchDialog( this, "Etext Search", true);
searchDlg->setCaption( tr( "Etext Search" ));
// searchDlg->setLabel( "- searches etext");
connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
QString resultString;
QString string = searchDlg->searchString;
Lview->deselect();
searchDlg->show();
searchDlg->result();
}
}
void Gutenbrowser::search_slot( ) {
int line, col;
if (!searchDlg /*&& !loadCheck */)
return;
Lview->getCursorPosition(&line,&col);
QString to_find_string=searchDlg->get_text();
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h
index 29d0329..61531c0 100644
--- a/noncore/apps/opie-reader/BuffDoc.h
+++ b/noncore/apps/opie-reader/BuffDoc.h
@@ -1,122 +1,122 @@
#ifndef __BuffDoc_h
#define __BuffDoc_h
#include "useqpe.h"
#include "ZText.h"
#include "Aportis.h"
#include "ztxt.h"
#include "ppm_expander.h"
#include "CDrawBuffer.h"
#include "CFilter.h"
#include <qfontmetrics.h>
#include <qmessagebox.h>
class BuffDoc
{
CDrawBuffer lastword;
CSizeBuffer lastsizes, allsizes;
size_t laststartline;
bool lastispara;
CExpander* exp;
CFilterChain* filt;
public:
void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
- {
- if (exp == NULL)
- {
- data = NULL;
- len = 0;
- }
- else
- {
- exp->setSaveData(data, len, src, srclen);
- }
- }
+ {
+ if (exp == NULL)
+ {
+ data = NULL;
+ len = 0;
+ }
+ else
+ {
+ exp->setSaveData(data, len, src, srclen);
+ }
+ }
void putSaveData(unsigned char*& src, unsigned short& srclen)
- {
- if (exp != NULL)
- {
- exp->putSaveData(src, srclen);
- }
- }
+ {
+ if (exp != NULL)
+ {
+ exp->putSaveData(src, srclen);
+ }
+ }
#ifdef USEQPE
void suspend() { if (exp != NULL) exp->suspend(); }
void unsuspend() { if (exp != NULL) exp->unsuspend(); }
#else
void suspend() {}
void unsuspend() {}
#endif
~BuffDoc()
- {
- delete filt;
- delete exp;
- }
+ {
+ delete filt;
+ delete exp;
+ }
BuffDoc()
- {
- exp = NULL;
- filt = NULL;
- lastword.empty();
-// // qDebug("Buffdoc created");
- }
+ {
+ exp = NULL;
+ filt = NULL;
+ lastword.empty();
+ // odebug << "Buffdoc created" << oendl;
+ }
bool empty() { return (exp == NULL); }
void setfilter(CFilterChain* _f)
- {
- if (filt != NULL) delete filt;
- filt = _f;
- filt->setsource(exp);
- }
+ {
+ if (filt != NULL) delete filt;
+ filt = _f;
+ filt->setsource(exp);
+ }
CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
bool iseol() { return (lastword[0] == '\0'); }
int openfile(QWidget* _parent, const char *src);
tchar getch()
- {
- tchar ch = UEOF;
- CStyle sty;
- if (exp != NULL)
- {
- filt->getch(ch, sty);
- }
- return ch;
- }
+ {
+ tchar ch = UEOF;
+ CStyle sty;
+ if (exp != NULL)
+ {
+ filt->getch(ch, sty);
+ }
+ return ch;
+ }
void getch(tchar& ch, CStyle& sty)
- {
- if (exp != NULL)
- {
- filt->getch(ch, sty);
- }
- else
- ch = UEOF;
- }
+ {
+ if (exp != NULL)
+ {
+ filt->getch(ch, sty);
+ }
+ else
+ ch = UEOF;
+ }
void setwidth(int w) { if (exp != NULL) exp->setwidth(w); }
QImage* getPicture(unsigned long tgt) { return (exp == NULL) ? NULL : exp->getPicture(tgt); }
unsigned int startSection() { return (exp == NULL) ? 0 : exp->startSection(); }
unsigned int endSection() { return (exp == NULL) ? 0 : exp->endSection(); }
unsigned int locate() { return (exp == NULL) ? 0 : laststartline; }
unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); }
void setContinuous(bool _b) { if (exp != NULL) exp->setContinuous(_b); }
MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); }
linkType hyperlink(unsigned int n, QString& wrd);
size_t getHome() { return ((exp != NULL) ? exp->getHome() : 0); }
void locate(unsigned int n);
bool getline(CDrawBuffer* buff, int w, unsigned char _border);
bool getline(CDrawBuffer* buff, int w, int cw, unsigned char _border);
void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); }
int getpara(CBuffer& buff)
- {
- tchar ch;
- int i = 0;
- while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
- buff[i] = '\0';
- if (i == 0 && ch == UEOF) i = -1;
- laststartline = exp->locate();
- return i;
- }
+ {
+ tchar ch;
+ int i = 0;
+ while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
+ buff[i] = '\0';
+ if (i == 0 && ch == UEOF) i = -1;
+ laststartline = exp->locate();
+ return i;
+ }
void saveposn(size_t posn) { exp->saveposn(posn); }
void writeposn(size_t posn) { exp->writeposn(posn); }
bool forward(size_t& loc) { return exp->forward(loc); }
bool back(size_t& loc) { return exp->back(loc); }
bool hasnavigation() { return exp->hasnavigation(); }
};
#endif
diff --git a/noncore/apps/opie-reader/CEncoding.h b/noncore/apps/opie-reader/CEncoding.h
index 463fba9..df0104a 100644
--- a/noncore/apps/opie-reader/CEncoding.h
+++ b/noncore/apps/opie-reader/CEncoding.h
@@ -15,60 +15,60 @@ public:
CEncoding() : parent(NULL) {}
void setparent(CExpander* p) { parent = p; }
virtual ~CEncoding() {};
};
class CUtf8 : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CUcs16be : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CUcs16le : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class Ccp1252 : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CPalm : public Ccp1252
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CAscii : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
#include "CEncoding_tables.h"
class CGeneral8Bit : public CEncoding
{
int m_index;
public:
CGeneral8Bit(int _i) : m_index(_i)
- {
-// qDebug("8Bit:%d", _i);
-// qDebug("%s", unicodetable::iterator(_i)->mime);
- }
+ {
+// odebug << "8Bit: " << _i << oendl;
+// odebug << unicodetable::iterator(_i)->mime << oendl;
+ }
void getch(tchar& ch, CStyle& sty)
- {
- parent->getch(ch, sty);
- ch = unicodetable::unicodevalue(m_index, ch);
- }
+ {
+ parent->getch(ch, sty);
+ ch = unicodetable::unicodevalue(m_index, ch);
+ }
};
#endif
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
index 7b21d3e..9fae245 100644
--- a/noncore/apps/opie-reader/CExpander.h
+++ b/noncore/apps/opie-reader/CExpander.h
@@ -1,151 +1,151 @@
#ifndef __CExpander_h
#define __CExpander_h
#ifndef _WINDOWS
#include <unistd.h>
#endif
#include <stdio.h>
#include <time.h>
#include <qmessagebox.h>
#include "useqpe.h"
#include "config.h"
#include "StyleConsts.h"
#include "Markups.h"
#include "names.h"
#include "linktype.h"
class QImage;
class Bkmk;
template<class T>
class CList;
class CCharacterSource
{
public:
virtual void getch(tchar&, CStyle&) = 0;
virtual linkType hyperlink(unsigned int n, QString&) = 0;
};
class CExpander
{
protected:
size_t m_homepos;
bool m_continuous;
char* fname;
bool bSuspended;
size_t suspos;
time_t sustime;
int m_scrWidth;
unsigned long m_currentstart, m_currentend;
public:
#ifdef USEQPE
- virtual void suspend() = 0;
+ virtual void suspend() = 0;
virtual void unsuspend() = 0;
#endif
size_t getHome() { return m_homepos; }
CExpander() : m_homepos(0), fname(NULL), m_scrWidth(240), m_currentstart(1), m_currentend(0) {};
virtual ~CExpander() { if (fname != NULL) delete [] fname; };
int openfile(const char *src)
- {
- bSuspended = false;
- fname = strdup(src);
- return OpenFile(src);
- }
+ {
+ bSuspended = false;
+ fname = strdup(src);
+ return OpenFile(src);
+ }
virtual int OpenFile(const char *src) = 0;
virtual unsigned int locate() = 0;
virtual void locate(unsigned int n) = 0;
virtual bool hasrandomaccess() = 0;
virtual void sizes(unsigned long& file, unsigned long& text) = 0;
virtual CList<Bkmk>* getbkmklist() { return NULL; }
virtual void getch(tchar& ch, CStyle& sty)
- {
- int ich = getch();
- ch = (ich == EOF) ? UEOF : ich;
- sty.unset();
- }
+ {
+ int ich = getch();
+ ch = (ich == EOF) ? UEOF : ich;
+ sty.unset();
+ }
virtual int getch() = 0;
virtual linkType hyperlink(unsigned int n, QString& wrd)
- {
- locate(n);
- return eLink;
- }
+ {
+ locate(n);
+ return eLink;
+ }
virtual MarkupType PreferredMarkup() = 0;
virtual void saveposn(size_t posn) {}
virtual void writeposn(size_t posn) {}
virtual bool forward(size_t& loc) { return false; }
virtual bool back(size_t& loc) { return false; }
virtual bool hasnavigation() { return false; }
unsigned long startSection()
- {
- unsigned long current = locate();
- if (m_currentstart > current || current > m_currentend)
- {
- start2endSection();
- }
- return m_currentstart;
- }
+ {
+ unsigned long current = locate();
+ if (m_currentstart > current || current > m_currentend)
+ {
+ start2endSection();
+ }
+ return m_currentstart;
+ }
unsigned long endSection()
- {
- unsigned long current = locate();
- if (m_currentstart > current || current > m_currentend)
- {
- start2endSection();
- }
- return m_currentend;
- }
+ {
+ unsigned long current = locate();
+ if (m_currentstart > current || current > m_currentend)
+ {
+ start2endSection();
+ }
+ return m_currentend;
+ }
virtual void start2endSection()
- {
- m_currentstart = 0;
- unsigned long file;
- sizes(file, m_currentend);
- }
+ {
+ m_currentstart = 0;
+ unsigned long file;
+ sizes(file, m_currentend);
+ }
virtual QImage* getPicture(unsigned long tgt) { return NULL; }
void setContinuous(bool _b) { m_continuous = _b; }
#ifdef USEQPE
virtual void suspend(FILE*& fin)
{
- bSuspended = true;
- suspos = ftell(fin);
- fclose(fin);
- fin = NULL;
- sustime = time(NULL);
+ bSuspended = true;
+ suspos = ftell(fin);
+ fclose(fin);
+ fin = NULL;
+ sustime = time(NULL);
}
virtual void unsuspend(FILE*& fin)
{
- if (bSuspended)
- {
- bSuspended = false;
- int delay = time(NULL) - sustime;
- if (delay < 10) sleep(10-delay);
- fin = fopen(fname, "rb");
- for (int i = 0; fin == NULL && i < 5; i++)
- {
- sleep(5);
- fin = fopen(fname, "rb");
- }
- if (fin == NULL)
- {
- QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
- exit(0);
- }
- suspos = fseek(fin, suspos, SEEK_SET);
- }
+ if (bSuspended)
+ {
+ bSuspended = false;
+ int delay = time(NULL) - sustime;
+ if (delay < 10) sleep(10-delay);
+ fin = fopen(fname, "rb");
+ for (int i = 0; fin == NULL && i < 5; i++)
+ {
+ sleep(5);
+ fin = fopen(fname, "rb");
+ }
+ if (fin == NULL)
+ {
+ QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
+ exit(0);
+ }
+ suspos = fseek(fin, suspos, SEEK_SET);
+ }
}
#endif
virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
- {
- len = srclen;
- data = new unsigned char[len];
- memcpy(data, src, len);
- }
+ {
+ len = srclen;
+ data = new unsigned char[len];
+ memcpy(data, src, len);
+ }
virtual void putSaveData(unsigned char*& src, unsigned short& srclen)
- {
- if (srclen != 0)
- {
- qDebug("Don't know what to do with non-zero save data");
- }
- }
+ {
+ if (srclen != 0)
+ {
+ qDebug("Don't know what to do with non-zero save data");
+ }
+ }
void setwidth(int w) { m_scrWidth = w; }
};
#endif
diff --git a/noncore/apps/opie-reader/Filedata.h b/noncore/apps/opie-reader/Filedata.h
index 096dd31..1b85b71 100644
--- a/noncore/apps/opie-reader/Filedata.h
+++ b/noncore/apps/opie-reader/Filedata.h
@@ -1,51 +1,51 @@
#ifndef __FILEDATA_H
#define __FILEDATA_H
#include <time.h>
class CFiledata
{
unsigned char* data;
bool m_own;
public:
CFiledata(tchar* d)
- {
- data = (unsigned char*)d;
- m_own = false;
- }
+ {
+ data = (unsigned char*)d;
+ m_own = false;
+ }
CFiledata(time_t dt, tchar* nm)
- {
- int nlen = ustrlen(nm)+1;
- data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen];
- *((time_t *)data) = dt;
- memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen);
- m_own = true;
- }
+ {
+ int nlen = ustrlen(nm)+1;
+ data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen];
+ *((time_t *)data) = dt;
+ memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen);
+ m_own = true;
+ }
~CFiledata()
- {
- if (m_own && data != NULL)
- {
- delete [] data;
-// qDebug("~Filedata: deleting");
- }
- else
- {
-// qDebug("~Filedata: not deleting");
- }
- }
+ {
+ if (m_own && data != NULL)
+ {
+ delete [] data;
+// odebug << "~Filedata: deleting" << oendl;
+ }
+ else
+ {
+// odebug << "~Filedata: not deleting" << oendl;
+ }
+ }
tchar* name() const { return (tchar*)(data+sizeof(time_t)); }
time_t date() { return *((time_t *)data); }
void setdate(time_t _t) { *((time_t *)data) = _t; }
unsigned char* content() { return data; }
size_t length() const { return sizeof(time_t)+sizeof(tchar)*(ustrlen(name())+1); }
bool operator==(const CFiledata& rhs)
- {
- return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0));
- }
+ {
+ return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0));
+ }
bool samename(const CFiledata& rhs)
- {
- return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0);
- }
+ {
+ return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0);
+ }
};
#endif
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h
index 5681496..e56b619 100644
--- a/noncore/apps/opie-reader/FontControl.h
+++ b/noncore/apps/opie-reader/FontControl.h
@@ -1,153 +1,153 @@
#ifndef __FONTCONTROL_H
#define __FONTCONTROL_H
#include <qfontdatabase.h>
#include <qfontmetrics.h>
#include "StyleConsts.h"
class FontControl
{
int * m_fontsizes;
int m_size, g_size;
QString m_fontname;
QString m_fixedfontname;
int m_maxsize;
bool m_hasCourier;
int m_leading, m_extraspace;
unsigned char m_basesize;
public:
void setBaseSize(unsigned char _s) { m_basesize = _s; }
unsigned char getBaseSize() { return m_basesize; }
int gzoom();
FontControl(QString n = "helvetica", int size = 10)
- :
- m_fontsizes(NULL), m_hasCourier(false), m_leading(0), m_extraspace(0)
+ :
+ m_fontsizes(NULL), m_hasCourier(false), m_leading(0), m_extraspace(0)
{
- ChangeFont(n, size);
+ ChangeFont(n, size);
}
~FontControl()
- {
- if (m_fontsizes != NULL) delete [] m_fontsizes;
- }
+ {
+ if (m_fontsizes != NULL) delete [] m_fontsizes;
+ }
void hasCourier(bool _b, const QString& _nm)
- {
- m_hasCourier = _b;
- m_fixedfontname = _nm;
- }
+ {
+ m_hasCourier = _b;
+ m_fixedfontname = _nm;
+ }
QString& fixedfontname() { return m_fixedfontname; }
bool hasCourier() { return m_hasCourier; }
QString name() { return m_fontname; }
int currentsize() { return m_fontsizes[m_size]; }
int getsize(const CStyle& size)
- {
- int tgt = m_size+size.getFontSize();
- if (tgt < 0)
- {
- tgt = 0;
- }
- if (tgt >= m_maxsize)
- {
- tgt = m_maxsize - 1;
- }
- return m_fontsizes[tgt];
- }
+ {
+ int tgt = m_size+size.getFontSize();
+ if (tgt < 0)
+ {
+ tgt = 0;
+ }
+ if (tgt >= m_maxsize)
+ {
+ tgt = m_maxsize - 1;
+ }
+ return m_fontsizes[tgt];
+ }
int ascent()
{
- QFont f(name(), currentsize());
- QFontMetrics fm(f);
- return fm.ascent();
+ QFont f(name(), currentsize());
+ QFontMetrics fm(f);
+ return fm.ascent();
}
int ascent(const CStyle& ch)
{
- QFont f(name(), getsize(ch));
- QFontMetrics fm(f);
- return fm.ascent();
+ QFont f(name(), getsize(ch));
+ QFontMetrics fm(f);
+ return fm.ascent();
}
int descent()
{
- QFont f(name(), currentsize());
- QFontMetrics fm(f);
- return fm.descent();
+ QFont f(name(), currentsize());
+ QFontMetrics fm(f);
+ return fm.descent();
}
int descent(const CStyle& ch)
{
- QFont f(name(), getsize(ch));
- QFontMetrics fm(f);
- return fm.descent();
+ QFont f(name(), getsize(ch));
+ QFontMetrics fm(f);
+ return fm.descent();
}
int lineSpacing()
{
- QFont f(name(), currentsize());
- QFontMetrics fm(f);
- return fm.lineSpacing();
+ QFont f(name(), currentsize());
+ QFontMetrics fm(f);
+ return fm.lineSpacing();
}
int lineSpacing(const CStyle& ch)
{
- QFont f(name(), getsize(ch));
- QFontMetrics fm(f);
- return fm.lineSpacing();
+ QFont f(name(), getsize(ch));
+ QFontMetrics fm(f);
+ return fm.lineSpacing();
}
bool decreasesize()
- {
+ {
/*
- if (--m_size < 0)
- {
- m_size = 0;
- return false;
- }
- else return true;
+ if (--m_size < 0)
+ {
+ m_size = 0;
+ return false;
+ }
+ else return true;
*/
- if (g_size-- == m_size)
- {
- if (--m_size < 0)
- {
- m_size = 0;
- }
- }
-// qDebug("Font:%d Graphics:%d", m_size, g_size);
- return true;
- }
+ if (g_size-- == m_size)
+ {
+ if (--m_size < 0)
+ {
+ m_size = 0;
+ }
+ }
+// odebug << "Font:" << m_size << " Graphics:" << g_size << oendl;
+ return true;
+ }
bool increasesize()
- {
+ {
/*
- if (++m_size >= m_maxsize)
- {
- m_size = m_maxsize - 1;
- return false;
- }
- else return true;
+ if (++m_size >= m_maxsize)
+ {
+ m_size = m_maxsize - 1;
+ return false;
+ }
+ else return true;
*/
- if (g_size++ == m_size)
- {
- if (++m_size >= m_maxsize)
- {
- m_size = m_maxsize - 1;
- }
- }
-// qDebug("Font:%d Graphics:%d", m_size, g_size);
- return true;
- }
+ if (g_size++ == m_size)
+ {
+ if (++m_size >= m_maxsize)
+ {
+ m_size = m_maxsize - 1;
+ }
+ }
+// odebug << "Font:" << m_size << " Graphics:" << g_size << oendl;
+ return true;
+ }
bool ChangeFont(QString& n)
- {
- return ChangeFont(n, currentsize());
- }
+ {
+ return ChangeFont(n, currentsize());
+ }
bool ChangeFont(QString& n, int tgt);
void setlead(int _lead)
- {
- m_leading = _lead;
- }
+ {
+ m_leading = _lead;
+ }
int getlead()
- {
- return m_leading;
- }
+ {
+ return m_leading;
+ }
void setextraspace(int _lead)
- {
- m_extraspace = _lead;
- }
+ {
+ m_extraspace = _lead;
+ }
int getextraspace()
- {
- return m_extraspace;
- }
+ {
+ return m_extraspace;
+ }
};
#endif
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
index 9339595..b0d4e00 100644
--- a/noncore/apps/opie-reader/Palm2QImage.cpp
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -1,308 +1,319 @@
/* -*- mode: c; indent-tabs-mode: nil; -*- */
+
+/* OPIE */
+#include <opie2/odebug.h>
+
+/* QT */
+#include <qimage.h>
+
+/* STD */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _WINDOWS
#include <unistd.h> /* for link */
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
-#include <qimage.h>
/***********************************************************************/
/***********************************************************************/
/***** *****/
/***** Code to decode the Palm image format to JPEG *****/
/***** *****/
/***********************************************************************/
/***********************************************************************/
#define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1]))
#define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3]))
#define PALM_IS_COMPRESSED_FLAG 0x8000
#define PALM_HAS_COLORMAP_FLAG 0x4000
#define PALM_HAS_TRANSPARENCY_FLAG 0x2000
#define PALM_DIRECT_COLOR_FLAG 0x0400
#define PALM_4_BYTE_FIELD_FLAG 0x0200
#define PALM_COMPRESSION_SCANLINE 0x00
#define PALM_COMPRESSION_RLE 0x01
#define PALM_COMPRESSION_PACKBITS 0x02
#define PALM_COMPRESSION_NONE 0xFF
#define PALM_COLORMAP_SIZE 232
typedef struct {
unsigned char red;
unsigned char green;
unsigned char blue;
} ColorMapEntry;
static ColorMapEntry Palm8BitColormap[] = {
- { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 },
- { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 },
- { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 },
- { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 },
+ { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 },
+ { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 },
+ { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 },
+ { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 },
{ 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 },
{ 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 },
{ 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 },
{ 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 },
{ 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 },
{ 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 },
{ 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 },
{ 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 },
{ 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 },
{ 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 },
{ 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 },
{ 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 },
{ 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 },
{ 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 },
{ 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 },
{ 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 },
{ 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 },
{ 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 },
{ 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 },
{ 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 },
{ 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 },
{ 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 },
{ 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 },
{ 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 },
{ 255, 51, 102 }, { 255, 0, 102 }, { 255, 255, 51 }, { 255, 204, 51 },
{ 255, 153, 51 }, { 255, 102, 51 }, { 255, 51, 51 }, { 255, 0, 51 },
{ 255, 255, 0 }, { 255, 204, 0 }, { 255, 153, 0 }, { 255, 102, 0 },
{ 255, 51, 0 }, { 255, 0, 0 }, { 204, 255, 102 }, { 204, 204, 102 },
{ 204, 153, 102 }, { 204, 102, 102 }, { 204, 51, 102 }, { 204, 0, 102 },
{ 204, 255, 51 }, { 204, 204, 51 }, { 204, 153, 51 }, { 204, 102, 51 },
{ 204, 51, 51 }, { 204, 0, 51 }, { 204, 255, 0 }, { 204, 204, 0 },
{ 204, 153, 0 }, { 204, 102, 0 }, { 204, 51, 0 }, { 204, 0, 0 },
{ 153, 255, 102 }, { 153, 204, 102 }, { 153, 153, 102 }, { 153, 102, 102 },
{ 153, 51, 102 }, { 153, 0, 102 }, { 153, 255, 51 }, { 153, 204, 51 },
{ 153, 153, 51 }, { 153, 102, 51 }, { 153, 51, 51 }, { 153, 0, 51 },
{ 153, 255, 0 }, { 153, 204, 0 }, { 153, 153, 0 }, { 153, 102, 0 },
{ 153, 51, 0 }, { 153, 0, 0 }, { 102, 255, 102 }, { 102, 204, 102 },
{ 102, 153, 102 }, { 102, 102, 102 }, { 102, 51, 102 }, { 102, 0, 102 },
{ 102, 255, 51 }, { 102, 204, 51 }, { 102, 153, 51 }, { 102, 102, 51 },
{ 102, 51, 51 }, { 102, 0, 51 }, { 102, 255, 0 }, { 102, 204, 0 },
{ 102, 153, 0 }, { 102, 102, 0 }, { 102, 51, 0 }, { 102, 0, 0 },
{ 51, 255, 102 }, { 51, 204, 102 }, { 51, 153, 102 }, { 51, 102, 102 },
{ 51, 51, 102 }, { 51, 0, 102 }, { 51, 255, 51 }, { 51, 204, 51 },
{ 51, 153, 51 }, { 51, 102, 51 }, { 51, 51, 51 }, { 51, 0, 51 },
{ 51, 255, 0 }, { 51, 204, 0 }, { 51, 153, 0 }, { 51, 102, 0 },
{ 51, 51, 0 }, { 51, 0, 0 }, { 0, 255, 102 }, { 0, 204, 102 },
{ 0, 153, 102 }, { 0, 102, 102 }, { 0, 51, 102 }, { 0, 0, 102 },
{ 0, 255, 51 }, { 0, 204, 51 }, { 0, 153, 51 }, { 0, 102, 51 },
{ 0, 51, 51 }, { 0, 0, 51 }, { 0, 255, 0 }, { 0, 204, 0 },
{ 0, 153, 0 }, { 0, 102, 0 }, { 0, 51, 0 }, { 17, 17, 17 },
{ 34, 34, 34 }, { 68, 68, 68 }, { 85, 85, 85 }, { 119, 119, 119 },
{ 136, 136, 136 }, { 170, 170, 170 }, { 187, 187, 187 }, { 221, 221, 221 },
{ 238, 238, 238 }, { 192, 192, 192 }, { 128, 0, 0 }, { 128, 0, 128 },
{ 0, 128, 0 }, { 0, 128, 128 }, { 0, 0, 0 }, { 0, 0, 0 },
{ 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
{ 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
{ 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
{ 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
{ 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
{ 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }};
static ColorMapEntry Palm1BitColormap[] = {{ 255, 255, 255 }, { 0, 0, 0 }};
static ColorMapEntry Palm2BitColormap[] = {
{ 255, 255, 255 }, { 192, 192, 192 }, { 128, 128, 128 }, { 0, 0, 0 }};
static ColorMapEntry Palm4BitColormap[] = {
{ 255, 255, 255 }, { 238, 238, 238 }, { 221, 221, 221 }, { 204, 204, 204 },
{ 187, 187, 187 }, { 170, 170, 170 }, { 153, 153, 153 }, { 136, 136, 136 },
{ 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 },
{ 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }};
QImage* Palm2QImage
(unsigned char *image_bytes_in, int byte_count_in)
{
unsigned int width, height, bytes_per_row, flags, next_depth_offset;
unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount;
unsigned int palm_red_bits, palm_green_bits, palm_blue_bits;
unsigned char *palm_ptr, *x_ptr, *imagedata, *inbyte, *rowbuf, *lastrow,
*imagedatastart, *palmimage;
ColorMapEntry *colormap;
palmimage = image_bytes_in;
width = READ_BIGENDIAN_SHORT(palmimage + 0);
height = READ_BIGENDIAN_SHORT(palmimage + 2);
bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4);
flags = READ_BIGENDIAN_SHORT(palmimage + 6);
bits_per_pixel = palmimage[8];
version = palmimage[9];
next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10);
transparent_index = palmimage[12];
compression_type = palmimage[13];
/* bytes 14 and 15 are reserved by Palm and always 0 */
-
+
#if 0
-// qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type);
+// odebug << "Palm image is " << width << "x" << height
+// << ", " << bits_per_pixel << " bpp, version " << version
+// << ", flags 0x" << flags << ", compression " << compression_type << oendl;
#endif
if (compression_type == PALM_COMPRESSION_PACKBITS) {
-// qDebug ("Image uses packbits compression; not yet supported");
+// odebug << "Image uses packbits compression; not yet supported" << oendl;
return NULL;
} else if ((compression_type != PALM_COMPRESSION_NONE) &&
(compression_type != PALM_COMPRESSION_RLE) &&
(compression_type != PALM_COMPRESSION_SCANLINE)) {
-// qDebug ("Image uses unknown compression, code 0x%x", compression_type);
+// odebug << "Image uses unknown compression, code 0x" << compression_type << oendl;
return NULL;
}
/* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps:
-
+
1, 2, or 4 bit grayscale
8-bit StaticColor using the Palm standard colormap
8-bit PseudoColor using a user-specified colormap
16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue
-
+
Each of these can be compressed with one of four compression schemes,
"RLE", "Scanline", "PackBits", or none.
-
+
We begin by constructing the colormap.
*/
if (flags & PALM_HAS_COLORMAP_FLAG) {
-// qDebug("Palm images with custom colormaps are not currently supported.\n");
+// odebug << "Palm images with custom colormaps are not currently supported." << oendl;
return NULL;
} else if (bits_per_pixel == 1) {
colormap = Palm1BitColormap;
imagedatastart = palmimage + 16;
} else if (bits_per_pixel == 2) {
colormap = Palm2BitColormap;
imagedatastart = palmimage + 16;
} else if (bits_per_pixel == 4) {
colormap = Palm4BitColormap;
imagedatastart = palmimage + 16;
} else if (bits_per_pixel == 8) {
colormap = Palm8BitColormap;
imagedatastart = palmimage + 16;
} else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) {
colormap = NULL;
palm_red_bits = palmimage[16];
palm_green_bits = palmimage[17];
palm_blue_bits = palmimage[18];
-// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits);
+// odebug << "Bits:" << palm_red_bits << ", " << palm_green_bits << ", " << palm_blue_bits << oendl;
if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) {
-// qDebug("Can't handle this format DirectColor image -- too wide in some color (%d:%d:%d)\n", palm_red_bits, palm_green_bits, palm_blue_bits);
+// odebug << "Can't handle this format DirectColor image -- too wide in some color ("
+// << palm_red_bits << ":" << palm_green_bits << ":" << palm_blue_bits << oendl;
return NULL;
}
if (bits_per_pixel > (8 * sizeof(unsigned long))) {
-// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel);
+// odebug << "Can't handle this format DirectColor image -- too many bits per pixel ("
+// << bits_per_pixel << ")" << oendl;
return NULL;
}
imagedatastart = palmimage + 24;
} else {
-// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel);
+// odebug << "Unknown bits-per-pixel of " << bits_per_pixel << " encountered" << oendl;
return NULL;
}
#ifndef USEQPE
QImage* qimage = new QImage(width, height, 32);
#else
QImage* qimage = new QImage(width, height, 16);
#endif
/* row by row, uncompress the Palm image and copy it to the JPEG buffer */
rowbuf = new unsigned char[bytes_per_row * width];
lastrow = new unsigned char[bytes_per_row * width];
for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) {
-// qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row);
+// odebug << "inval:" << inval << " palm_ptr:" << palm_ptr << " x_ptr:" << x_ptr
+// << " bpr:" << bytes_per_row << oendl;
/* first, uncompress the Palm image */
if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
for (j = 0; j < bytes_per_row; ) {
- incount = *palm_ptr++;
- inval = *palm_ptr++;
- memset(rowbuf + j, inval, incount);
- j += incount;
+ incount = *palm_ptr++;
+ inval = *palm_ptr++;
+ memset(rowbuf + j, inval, incount);
+ j += incount;
}
} else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) {
for (j = 0; j < bytes_per_row; j += 8) {
- incount = *palm_ptr++;
- inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8;
- for (inbit = 0; inbit < inval; inbit += 1) {
- if (incount & (1 << (7 - inbit)))
- rowbuf[j + inbit] = *palm_ptr++;
- else
- rowbuf[j + inbit] = lastrow[j + inbit];
- }
+ incount = *palm_ptr++;
+ inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8;
+ for (inbit = 0; inbit < inval; inbit += 1) {
+ if (incount & (1 << (7 - inbit)))
+ rowbuf[j + inbit] = *palm_ptr++;
+ else
+ rowbuf[j + inbit] = lastrow[j + inbit];
+ }
}
memcpy (lastrow, rowbuf, bytes_per_row);
} else if (((flags & PALM_IS_COMPRESSED_FLAG) &&
(compression_type == PALM_COMPRESSION_NONE)) ||
((flags & PALM_IS_COMPRESSED_FLAG) == 0))
{
memcpy (rowbuf, palm_ptr, bytes_per_row);
palm_ptr += bytes_per_row;
}
else {
- qDebug("Case 4");
- qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true");
- qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true");
- qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true");
- qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true");
- qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true");
+ odebug << "Case 4" << oendl;
+ odebug << "Is compressed:" << (((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "Has colourmap:" << (((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "Has transparency:" << (((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "Direct colour:" << (((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "four byte field:" << (((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true") << oendl;
memcpy (rowbuf, palm_ptr, bytes_per_row);
palm_ptr += bytes_per_row;
}
/* next, write it to the GDK bitmap */
if (colormap) {
mask = (1 << bits_per_pixel) - 1;
for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) {
- inval = ((*inbyte) & (mask << inbit)) >> inbit;
- /* correct for oddity of the 8-bit color Palm pixmap... */
- if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231;
- /* now lookup the correct color and set the pixel in the GTK bitmap */
- QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue);
+ inval = ((*inbyte) & (mask << inbit)) >> inbit;
+ /* correct for oddity of the 8-bit color Palm pixmap... */
+ if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231;
+ /* now lookup the correct color and set the pixel in the GTK bitmap */
+ QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue);
qimage->setPixel(j, i, colour);
- if (!inbit) {
- ++inbyte;
- inbit = 8 - bits_per_pixel;
- } else {
- inbit -= bits_per_pixel;
- }
+ if (!inbit) {
+ ++inbyte;
+ inbit = 8 - bits_per_pixel;
+ } else {
+ inbit -= bits_per_pixel;
+ }
}
} else if (!colormap &&
bits_per_pixel == 16) {
for (inbyte = rowbuf, j = 0; j < width; ++j) {
- inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
+ inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
/*
- qDebug ("pixel is %d,%d (%d:%d:%d)",
- j, i,
- ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
- ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
- ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
+ odebug << "pixel is " << j << "," << i << " ("
+ << (((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits)) << ":"
+ << (((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits)) << ":"
+ << (((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)) << ")" << oendl;
*/
- QRgb colour = qRgb(
- ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
+ QRgb colour = qRgb(
+ ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
qimage->setPixel(j, i, colour);
- inbyte += 2;
+ inbyte += 2;
}
}
}
delete [] rowbuf;
delete [] lastrow;
return qimage;
}
QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
{
-//// qDebug("hrule [%d, %d]", w, h);
+// odebug << "hrule [" << w << ", " << h << "]" << oendl;
QPixmap* qimage = new QPixmap(w, h);
qimage->fill(QColor(r,g,b));
QImage* ret = new QImage(qimage->convertToImage());
delete qimage;
return ret;
}
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h
index dfbdfb9..f89de63 100644
--- a/noncore/apps/opie-reader/QTReader.h
+++ b/noncore/apps/opie-reader/QTReader.h
@@ -1,240 +1,240 @@
#ifndef __QTREADER_H
#define __QTREADER_H
//#define _SCROLLPIPE
#include <qwidget.h>
//#include <qpainter.h>
#include "my_list.h"
#include "BuffDoc.h"
#include "FontControl.h"
//#include <qtimer.h>
class CDrawBuffer;
//class CBuffer;
class QPainter;
class QTimer;
class QPixmap;
class QTReader : public QWidget
{
Q_OBJECT
- static tchar pluckernextpart[];
- static tchar jplucknextpart[];
+ static tchar pluckernextpart[];
+ static tchar jplucknextpart[];
friend class QTReaderApp;
void suspend();
void increaseScroll();
void reduceScroll();
void drawText(QPainter& p, int x, int y, tchar* text);
int m_delay;
unsigned int m_overlap;
bool m_autoScroll, m_swapmouse;
void autoscroll();
QTimer* timer;
int m_scrolldy1, m_scrolldy2, m_encd, m_scrollpart;
void focusInEvent(QFocusEvent*);
void focusOutEvent(QFocusEvent*);
void processmousepositionevent( QMouseEvent* _e );
void processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno);
bool ChangeFont(int);
bool getline(CDrawBuffer*);
int m_charWidth;
int m_charpc;
unsigned char m_border;
FontControl m_fontControl;
void setBaseSize(unsigned char _s) { m_fontControl.setBaseSize(_s); }
unsigned char getBaseSize() { return m_fontControl.getBaseSize(); }
#ifdef _SCROLLPIPE
FILE* m_pipeout;
QString m_pipetarget;
bool m_isPaused;
bool m_pauseAfterEachPara;
#endif
public:
QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
// QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
~QTReader();
void zoomin();
void zoomout();
void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
- {
- buffdoc.setSaveData(data, len, src, srclen);
- }
+ {
+ buffdoc.setSaveData(data, len, src, srclen);
+ }
void putSaveData(unsigned char*& src, unsigned short& srclen)
- {
- buffdoc.putSaveData(src, srclen);
- }
+ {
+ buffdoc.putSaveData(src, srclen);
+ }
bool empty();
void setContinuous(bool _b);
void toggle_autoscroll();
void setautoscroll(bool);
void disableAutoscroll() { m_autoScroll = false; }
void copy()
{
/*
size_t nd = locate();
- jumpto(m_mark);
+ jumpto(m_mark);
QString text;
while (m_mark < nd)
{
text += buffdoc.getch();
m_mark++;
}
QApplication::clipboard()->setText(text);
jumpto(nd);
*/
};
void clear() {};
void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); };
/*
void setText(bool oldfile)
{
- if (oldfile)
- {
- m_string = m_lastfile;
- load_file((const tchar*)m_string);
- }
- else
- {
- m_string = QString::null;
- }
+ if (oldfile)
+ {
+ m_string = m_lastfile;
+ load_file((const tchar*)m_string);
+ }
+ else
+ {
+ m_string = QString::null;
+ }
};
*/
void setlead(int _lead)
- {
- m_fontControl.setlead(_lead);
- }
+ {
+ m_fontControl.setlead(_lead);
+ }
int getlead()
- {
- return m_fontControl.getlead();
- }
+ {
+ return m_fontControl.getlead();
+ }
void setextraspace(int _lead)
- {
- m_fontControl.setextraspace(_lead);
- }
+ {
+ m_fontControl.setextraspace(_lead);
+ }
int getextraspace()
- {
- return m_fontControl.getextraspace();
- }
+ {
+ return m_fontControl.getextraspace();
+ }
void setpagemode(bool _b)
{
- m_bpagemode = _b;
+ m_bpagemode = _b;
}
void setmono(bool _b)
{
- m_bMonoSpaced = _b;
- ChangeFont(m_fontControl.currentsize());
- locate(pagelocate());
+ m_bMonoSpaced = _b;
+ ChangeFont(m_fontControl.currentsize());
+ locate(pagelocate());
}
void setencoding(int _f)
- {
- m_encd = _f;
- setfilter(getfilter());
- }
+ {
+ m_encd = _f;
+ setfilter(getfilter());
+ }
MarkupType PreferredMarkup();
CEncoding* getencoding()
- {
-// qDebug("m_encd:%d", m_encd);
- switch (m_encd)
- {
- case 4:
-// qDebug("palm");
- return new CPalm;
- case 1:
-// qDebug("utf8");
- return new CUtf8;
- case 2:
-// qDebug("ucs16be");
- return new CUcs16be;
- case 3:
-// qDebug("ucs16le");
- return new CUcs16le;
- case 0:
-// qDebug("ascii");
- return new CAscii;
- default:
- return new CGeneral8Bit(m_encd-MAX_ENCODING+1);
- }
- }
+ {
+// odebug << "m_encd:" << m_encd << oendl;
+ switch (m_encd)
+ {
+ case 4:
+// odebug << "palm" << oendl;
+ return new CPalm;
+ case 1:
+// odebug << "utf8" << oendl;
+ return new CUtf8;
+ case 2:
+// odebug << "ucs16be" << oendl;
+ return new CUcs16be;
+ case 3:
+// odebug << "ucs16le" << oendl;
+ return new CUcs16le;
+ case 0:
+// odebug << "ascii" << oendl;
+ return new CAscii;
+ default:
+ return new CGeneral8Bit(m_encd-MAX_ENCODING+1);
+ }
+ }
CFilterChain* getfilter()
{
CFilterChain * filt = new CFilterChain(getencoding());
if (bstripcr) filt->addfilter(new stripcr);
if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml);
if (bdehyphen) filt->addfilter(new dehyphen);
if (bunindent) filt->addfilter(new unindent);
if (brepara) filt->addfilter(new repara);
if (bonespace) filt->addfilter(new OnePara);
if (bindenter) filt->addfilter(new indenter(bindenter));
if (bdblspce) filt->addfilter(new dblspce);
#ifdef REPALM
if (brepalm) filt->addfilter(new repalm);
#endif
if (bremap) filt->addfilter(new remap);
if (bdepluck) filt->addfilter(new DePluck(pluckernextpart));
if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart));
if (bmakebold) filt->addfilter(new embolden);
if (bfulljust) filt->addfilter(new FullJust);
return filt;
}
private slots:
void goHome();
void goBack();
void goForward();
- void doscroll();
+ void doscroll();
void drawIt( QPainter * );
void paintEvent( QPaintEvent * );
// void resizeEvent( QResizeEvent * p ) { update(); }
void keyPressEvent(QKeyEvent*);
void drawFonts(QPainter*);
private:
void setTwoTouch(bool _b);
void init();
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
// void mouseDoubleClickEvent( QMouseEvent* );
QString m_string, m_fontname;
void setfont();
//myoutput stuff
private:
bool mouseUpOn;
linkType getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
bool m_twotouch, m_touchone;
size_t m_startpos, m_startoffset;
void dopageup(unsigned int);
void dopageup();
void lineDown();
void lineUp();
void dopagedn();
long real_delay();
int m_textsize;
int m_lastwidth, m_lastheight;
CBufferFace<CDrawBuffer*> textarray;
CBufferFace<size_t> locnarray;
unsigned int numlines;
// bool m_showlast;
bool bstripcr, btextfmt, bstriphtml, bdehyphen, bdepluck, bdejpluck, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace, bfulljust;
#ifdef REPALM
bool brepalm;
#endif
bool m_bpagemode, m_bMonoSpaced, m_continuousDocument;
unsigned char bindenter;
QString m_lastfile;
size_t m_lastposn;
public:
bool bDoUpdates;
void NavUp();
void NavDown();
tchar getch() { return buffdoc.getch(); }
bool synch(size_t, size_t);
bool tight;
bool load_file(const char *newfile, unsigned int lcn=0);
BuffDoc buffdoc;
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h
index ab6f60e..fe3eebf 100644
--- a/noncore/apps/opie-reader/QTReaderApp.h
+++ b/noncore/apps/opie-reader/QTReaderApp.h
@@ -1,300 +1,300 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qt Palmtop Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __QTREADERAPP_H
#define __QTREADERAPP_H
//#define _SCROLLPIPE
//#define __ISEARCH
//#define MAX_ENCODING 6
#define MAX_ACTIONS 5
#include "useqpe.h"
#include <sys/timeb.h>
#include <qmainwindow.h>
#include "CExpander.h"
#include "CEncoding.h"
#include <qlist.h>
//#include <qpe/filemanager.h>
#include <qmap.h>
#include <qlineedit.h>
#include <qstack.h>
#include <qlistbox.h>
//#include "Queue.h"
class QWidgetStack;
class QToolButton;
class QPopupMenu;
class QToolBar;
-#ifdef USEQPE
+#ifdef USEQPE
class QToolBar;
-class QMenuBar;
+class QMenuBar;
#endif
class CBkmkSelector;
class QProgressBar;
class QAction;
class CAnnoEdit;
class QFloatBar;
class CDrawBuffer;
class QTReader;
class QImage;
class Config;
enum ActionTypes
{
cesNone = 0,
cesOpenFile,
cesAutoScroll,
cesActionMark,
cesActionAnno,
cesFullScreen,
cesZoomIn,
cesZoomOut,
cesBack,
cesForward,
cesHome,
cesPageUp,
cesPageDown,
cesLineUp,
cesLineDown,
cesStartDoc,
cesEndDoc
};
/*
*m_preferences_action, *m_close_action *m_info_action, *m_touch_action,
*m_find_action, *m_jump_action, *m_setfont_action *m_goto_action,
*m_delete_action; *m_autogen_action, *m_clear_action, *m_save_action;
*m_tidy_action, *m_startBlock_action, *m_endBlock_action;
*m_setenc_action, *m_setmono_action;
*/
enum ToolbarPolicy
{
cesSingle = 0,
cesMenuTool,
cesMultiple
};
enum regedit_type
{
cAutoGen,
cAddBkmk,
cJump,
cMonoSpace,
cSetTarget,
#ifdef _SCROLLPIPE
cSetPipeTarget,
#endif
cSetConfigName,
cMargin,
cExtraSpace,
cExtraLead
};
enum bkmk_action
{
cOpenFile,
cGotoBkmk,
cDelBkmk,
cRmBkmkFile,
cLdConfig,
cRmConfig,
cExportLinks
};
enum fontselector_action
{
cChooseFont,
cChooseEncoding
};
#ifdef __ISEARCH
struct searchrecord
{
QString s;
size_t pos;
searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {}
};
#endif
class infowin;
class GraphicWin;
class QTReaderApp : public QMainWindow
{
Q_OBJECT
- unsigned long m_savedpos;
+ unsigned long m_savedpos;
int m_debounce;
timeb m_lastkeytime;
bool m_annoIsEditing;
bool m_propogatefontchange, m_bFloatingDialog;
bool m_url_clipboard, m_url_localfile, m_url_globalfile;
fontselector_action m_fontAction;
void doAction(ActionTypes a, QKeyEvent* e);
- public:
+ public:
QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
~QTReaderApp();
void handlekey(QKeyEvent* e);
void hideEvent(QHideEvent*)
- {
- suspend();
- }
+ {
+ suspend();
+ }
void suspend();
void openFile( const QString & );
void setScrollState(bool _b);
protected:
void setfontHelper(const QString& lcn, int size = 0);
QAction* m_bkmkAvail, *m_actFullscreen;
CAnnoEdit* m_annoWin;
Bkmk* m_anno;
// void resizeEvent(QResizeEvent* e);
void closeEvent( QCloseEvent *e );
- void readbkmks();
- void do_mono(const QString&);
- void do_jump(const QString&);
- void do_settarget(const QString&);
+ void readbkmks();
+ void do_mono(const QString&);
+ void do_jump(const QString&);
+ void do_settarget(const QString&);
#ifdef _SCROLLPIPE
-// void do_setpipetarget(const QString&);
+// void do_setpipetarget(const QString&);
#endif
- void do_saveconfig(const QString&, bool);
- bool readconfig(const QString&, bool);
- bool PopulateConfig(const char*);
- ActionTypes ActNameToInt(const QString&);
+ void do_saveconfig(const QString&, bool);
+ bool readconfig(const QString&, bool);
+ bool PopulateConfig(const char*);
+ ActionTypes ActNameToInt(const QString&);
bool m_doAnnotation;
bool m_doDictionary;
bool m_doClipboard;
bool m_fullscreen;
bool m_loadedconfig;
public:
- void saveprefs();
+ void saveprefs();
public slots:
void setDocument(const QString&);
private slots:
#ifdef _SCRIPT
// void RunScript();
#endif
void SaveConfig();
void LoadConfig();
void TidyConfig();
void ExportLinks();
void zoomin();
void zoomout();
void chooseencoding();
void setfullscreen(bool sfs);
// void setcontinuous(bool sfs);
void setTwoTouch(bool _b);
void restoreFocus();
void OnAnnotation(bool _b)
- {
- m_doAnnotation = _b;
- }
+ {
+ m_doAnnotation = _b;
+ }
void OnDictionary(bool _b)
- {
- m_doDictionary = _b;
- }
+ {
+ m_doDictionary = _b;
+ }
void OnClipboard(bool _b)
- {
- m_doClipboard = _b;
- }
+ {
+ m_doClipboard = _b;
+ }
void OnWordSelected(const QString&, size_t, const QString&);
void OnURLSelected(const QString& href);
void showgraphic(QImage&);
void addAnno(const QString&, const QString&, size_t);
void addAnno(const QString&, const QString&);
void addanno();
void showAnnotation();
void do_setencoding(int i);
- void do_setfont(const QString&);
- void buttonActionSelected(QAction*);
-// void msgHandler(const QCString&, const QByteArray&);
- void monospace(bool);
- void jump();
- void settarget();
+ void do_setfont(const QString&);
+ void buttonActionSelected(QAction*);
+// void msgHandler(const QCString&, const QByteArray&);
+ void monospace(bool);
+ void jump();
+ void settarget();
#ifdef _SCROLLPIPE
-// void setpipetarget();
-// void setpause(bool);
+// void setpipetarget();
+// void setpause(bool);
#endif
-// void setspacing();
- void setfont();
- void clearBkmkList();
- void listBkmkFiles();
- void editMark();
- void autoScroll(bool);
- void addbkmk();
- void savebkmks();
-// void importFiles();
- void showprefs();
- void showtoolbarprefs();
- void infoClose();
- // void oldFile();
- void showinfo();
+// void setspacing();
+ void setfont();
+ void clearBkmkList();
+ void listBkmkFiles();
+ void editMark();
+ void autoScroll(bool);
+ void addbkmk();
+ void savebkmks();
+// void importFiles();
+ void showprefs();
+ void showtoolbarprefs();
+ void infoClose();
+ // void oldFile();
+ void showinfo();
// void indentplus();
// void indentminus();
void fileOpen();
void fileClose();
void editCopy();
void editFind();
void gotoStart();
void gotoEnd();
void pageup();
void pagedn();
void findNext();
void findClose();
void regClose();
#ifdef __ISEARCH
// void search( const QString& );
#else
void search();
#endif
void showEditTools();
// void stripcr(bool);
// void setfulljust(bool);
// void onespace(bool);
#ifdef REPALM
// void repalm(bool);
#endif
// void peanut(bool _b);
// void remap(bool);
// void embolden(bool);
// void autofmt(bool);
// void textfmt(bool);
// void striphtml(bool);
// void dehyphen(bool);
// void depluck(bool);
// void dejpluck(bool);
// void unindent(bool);
// void repara(bool);
// void dblspce(bool);
void pagemode(bool);
@@ -322,121 +322,121 @@ private slots:
QAction *m_loadconfig_action, *m_toolbarprefs_action, *m_tidyconfig_action;
QAction *m_exportlinks_action;
void addtoolbars(Config* config);
ToolbarPolicy m_tbpol, m_tbpolsave;
ToolBarDock m_tbposition;
bool m_tbmove, m_tbmovesave;
QToolBar* filebar();
QToolBar* viewbar();
QToolBar* navbar();
QToolBar* markbar();
void hidetoolbars();
void addfilebar(Config* _config, const QString& key, QAction* a);
void addviewbar(Config* _config, const QString& key, QAction* a);
void addnavbar(Config* _config, const QString& key, QAction* a);
void addmarkbar(Config* _config, const QString& key, QAction* a);
bool checkbar(Config* _config, const QString& key);
#ifdef _SCRIPT
void SaveScript(const char* sname);
#endif
/*
void setstate(unsigned char* _sd, unsigned short _sdlen);
void getstate(unsigned char*& data, unsigned short& len);
*/
void fileOpen2();
void readfilelist();
void savefilelist();
void updatefileinfo();
bool openfrombkmk(Bkmk*);
QString m_targetapp, m_targetmsg;
bool listbkmk(CList<Bkmk>*, const QString& _lab = QString::null);
QString usefilebrowser();
void do_regedit();
void colorChanged( const QColor &c );
void clear();
void updateCaption();
void do_autogen(const QString&);
void do_addbkmk(const QString&);
bool findNextBookmark(size_t start);
private:
QAction* m_scrollButton;
QAction* m_buttonAction[MAX_ACTIONS];
CBkmkSelector* bkmkselector;
ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget,
- m_upTarget, m_downTarget;
+ m_upTarget, m_downTarget;
bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll;
bool m_bcloseDisabled, m_disableesckey;
size_t searchStart;
#ifdef __ISEARCH
QStack<searchrecord>* searchStack;
bool dosearch(size_t start, CDrawBuffer& test, const QString& arg);
#else
bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg);
#endif
QWidgetStack *editorStack;
QTReader* reader;
QComboBox* m_fontSelector;
// QToolBar /* *menu,*/ *fileBar;
QToolBar *menubar, *fileBar, *navBar, *viewBar, *markBar;
-#ifdef USEQPE
- QMenuBar *mb;
-#else
- QMenuBar *mb;
-#endif
+#ifdef USEQPE
+ QMenuBar *mb;
+#else
+ QMenuBar *mb;
+#endif
QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
QLineEdit *searchEdit, *regEdit;
bool searchVisible;
bool regVisible;
bool m_fontVisible, m_twoTouch;
bool bFromDocView;
static unsigned long m_uid;
long unsigned get_unique_id() { return m_uid++; }
/*
void resizeEvent( QResizeEvent * r)
{
-// qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height());
-// qDebug("resize:(%u,%u)", r->size().width(), r->size().height());
+// odebug << "resize:(" << r->oldSize().width() << "," << r->oldSize().height() << ")" << oendl;
+// odebug << "resize:(" << r->size().width() << "," << r->size().height() << ")" << oendl;
// bgroup->move( width()-bgroup->width(), 0 );
}
*/
CList<Bkmk>* pBkmklist;
CList<Bkmk>* pOpenlist;
infowin* m_infoWin;
GraphicWin* m_graphicwin;
QProgressBar* pbar;
bool m_fBkmksChanged;
// int m_nRegAction;
regedit_type m_nRegAction;
bkmk_action m_nBkmkAction;
QString m_autogenstr;
bool m_dontSave;
};
//const int cAutoGen = 0;
//const int cAddBkmk = 1;
//const int cDelBkmk = 2;
//const int cGotoBkmk = 3;
//const int cRmBkmkFile = 4;
//const int cJump = 5;
//const int cMonoSpace = 6;
//const int cOverlap = 7;
//const int cSetTarget = 8;
//const int cOpenFile = 9;
//const int cSetPipeTarget = 10;
//const int cSetConfigName = 11;
//const int cMargin = 12;
//const int cExtraSpace = 14;
//const int cExtraLead = 15;
//const int cGfxSize = 16;
//const int cChooseFont = 2;
//const int cChooseEncoding = 1;
#endif
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h
index 9d8ec6a..969be87 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.h
+++ b/noncore/apps/tinykate/libkate/document/katedocument.h
@@ -1,127 +1,127 @@
/***************************************************************************
katedocument.h - description
-------------------
begin : Mon Jan 15 2001
copyright : (C) 2001 by Christoph "Crossfire" Cullmann
(C) 2002 by Joseph Wenninger
email : crossfire@babylon2k.de
jowenn@kde.org
-
+
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/*
Copyright (C) 1998, 1999 Jochen Wilhelmy
digisnap@cs.tu-berlin.de
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef kate_document_h
#define kate_document_h
#include <qobject.h>
#include <qlist.h>
#include <qcolor.h>
#include <qfont.h>
#include <qfontmetrics.h>
#include <qdatetime.h>
#include <qfileinfo.h>
#include "../view/kateview.h"
#include "katehighlight.h"
#include "katebuffer.h"
#include "katetextline.h"
#include <qptrdict.h>
class KateCmd;
class CachedFontMetrics : public QFontMetrics {
private:
short *warray[256];
public:
CachedFontMetrics(const QFont& f) : QFontMetrics(f) {
for (int i=0; i<256; i++) warray[i]=0;
}
~CachedFontMetrics() {
for (int i=0; i<256; i++)
if (warray[i]) delete[] warray[i];
}
int width(QChar c) {
uchar cell=c.cell();
uchar row=c.row();
short *wa=warray[row];
if (!wa) {
- // qDebug("create row: %d",row);
+ // odebug << "create row: " << row << oendl;
wa=warray[row]=new short[256];
for (int i=0; i<256; i++) wa[i]=-1;
}
if (wa[cell]<0) wa[cell]=(short) QFontMetrics::width(c);
return (int)wa[cell];
}
int width(QString s) { return QFontMetrics::width(s); }
};
class Attribute {
public:
Attribute() { ; };
QColor col;
QColor selCol;
bool bold;
bool italic;
};
class KateAction {
public:
enum Action {replace, wordWrap, wordUnWrap, newLine, delLine,
insLine, killLine};//, doubleLine, removeLine};
KateAction(Action, PointStruc &cursor, int len = 0,
const QString &text = QString::null);
Action action;
PointStruc cursor;
int len;
QString text;
KateAction *next;
};
class KateActionGroup {
public:
// the undo group types
enum { ugNone, //
ugPaste, // paste
ugDelBlock, // delete/replace selected text
ugIndent, // indent
ugUnindent, // unindent
ugComment, // comment
ugUncomment, // uncomment
ugReplace, // text search/replace
ugSpell, // spell check
ugInsChar, // char type/deleting
ugDelChar, // '' ''
@@ -134,97 +134,97 @@ class KateActionGroup {
void insertAction(KateAction *);
static const char * typeName(int type);
PointStruc start;
PointStruc end;
KateAction *action;
int undoType;
};
/**
The text document. It contains the textlines, controls the
document changing operations and does undo/redo. WARNING: do not change
the text contents directly in methods where this is not explicitly
permitted. All changes have to be made with some basic operations,
which are recorded by the undo/redo system.
@see TextLine
@author Jochen Wilhelmy
*/
class KateDocument: public Kate::Document
{
Q_OBJECT
friend class KateViewInternal;
friend class KateView;
friend class KateIconBorder;
public:
KateDocument(bool bSingleViewMode=false, bool bBrowserView=false, QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0);
~KateDocument();
protected:
QFont myFont, myFontBold, myFontItalic, myFontBI;
CachedFontMetrics myFontMetrics, myFontMetricsBold, myFontMetricsItalic, myFontMetricsBI;
public:
void setFont (QFont font);
QFont getFont () { return myFont; };
CachedFontMetrics getFontMetrics () { return myFontMetrics; };
virtual bool saveFile();
virtual KTextEditor::View *createView( QWidget *parent, const char *name );
virtual QString textLine( int line ) const;
virtual void insertLine( const QString &s, int line = -1 );
void insert_Line(const QString& s,int line=-1, bool update=true);
void remove_Line(int line,bool update=true);
- void replaceLine(const QString& s,int line=-1);
+ void replaceLine(const QString& s,int line=-1);
virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE );
virtual void removeLine( int line );
virtual int length() const;
virtual void setSelection( int row_from, int col_from, int row_to, int col_t );
virtual bool hasSelection() const;
virtual QString selection() const;
// only to make part work, don't change it !
bool m_bSingleViewMode;
// public interface
/**
* gets the number of lines
*/
virtual int numLines() const;
/**
* gets the last line number (numLines() -1)
*/
int lastLine() const {return numLines()-1;}
/**
gets the given line
@return the TextLine object at the given line
@see TextLine
*/
TextLine::Ptr getTextLine(int line) const;
/**
get the length in pixels of the given line
*/
int textLength(int line);
void setTabWidth(int);
int tabWidth() {return tabChars;}
void setReadOnly(bool);
bool isReadOnly() const;
void setNewDoc( bool );
bool isNewDoc() const;
virtual void setReadWrite( bool ){};
virtual bool isReadWrite() const {return true;}
virtual void setModified(bool);
virtual bool isModified() const;
void setSingleSelection(bool ss) {m_singleSelection = ss;}
bool singleSelection() {return m_singleSelection;}
void readConfig();
@@ -489,82 +489,82 @@ class KateDocument: public Kate::Document
QString encoding() { return myEncoding; };
void setWordWrap (bool on);
bool wordWrap () { return myWordWrap; };
void setWordWrapAt (uint col);
uint wordWrapAt () { return myWordWrapAt; };
signals:
void modStateChanged (KateDocument *doc);
void nameChanged (KateDocument *doc);
public:
QList<Kate::Mark> marks ();
public slots:
// clear buffer/filename - update the views
void flush ();
signals:
/**
The file has been saved (perhaps the name has changed). The main window
can use this to change its caption
*/
void fileNameChanged ();
public:
//end of line settings
enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2};
// for the DCOP interface
public:
void open (const QString &name=0);
public:
// wrap the text of the document at the column col
void wrapText (uint col);
public slots:
void applyWordWrap ();
private:
class KateDocPrivate
{
public:
bool hlSetByUser;
};
-
-
+
+
// BCI: Add a real d-pointer in the next BIC release
static QPtrDict<KateDocPrivate>* d_ptr;
static void cleanup_d_ptr()
{
delete d_ptr;
}
-
+
KateDocPrivate* d( const KateDocument* foo )
{
if ( !d_ptr ) {
d_ptr = new QPtrDict<KateDocPrivate>;
//qAddPostRoutine( cleanup_d_ptr );
}
KateDocPrivate* ret = d_ptr->find( (void*) foo );
if ( ! ret ) {
ret = new KateDocPrivate;
d_ptr->replace( (void*) foo, ret );
}
return ret;
}
-
+
void delete_d( const KateDocument* foo )
{
if ( d_ptr )
d_ptr->remove( (void*) foo );
}
};
#endif
diff --git a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
index a2c680f..78635b2 100644
--- a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
+++ b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
@@ -1,102 +1,108 @@
/****************************************************************************
** $Id$
**
** Implementation of QRegExp class
**
** Created : 950126
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#if QT_VERSION >=300
#error QRegExp3 is now in QT 3 use QRegExp instead
#endif
-#include "qarray.h"
-#include "qbitarray.h"
-#include "qcache.h"
-#include "qintdict.h"
-#include "qmap.h"
#if QT_VERSION < 300
#include "./qregexp3.h"
#else
#include "qregexp.h"
#endif
-#include "qstring.h"
-#include "qtl.h"
-#include "qvector.h"
+/* OPIE */
+#include <opie2/odebug.h>
+
+/* QT */
+#include <qarray.h>
+#include <qbitarray.h>
+#include <qcache.h>
+#include <qintdict.h>
+#include <qmap.h>
+#include <qstring.h>
+#include <qtl.h>
+#include <qvector.h>
+
+/* STD */
#include <limits.h>
/*
WARNING! Be sure to read qregexp.tex before modifying this file.
*/
/*!
\class QRegExp3 qregexp.h
\brief The QRegExp class provides pattern matching using regular expressions.
\ingroup tools
\ingroup misc
\ingroup shared
Regular expressions, "regexps", provide a way to find patterns
within text. This is useful in many contexts, for example:
<ol>
<li>\e Validation. A regexp can be used to check whether a piece of
text meets some criteria, e.g. is an integer or contains no
whitespace.
<li>\e Searching. Regexps provide a much more powerful means of
searching text than simple string matching does. For example we can
create a regexp which says "find one of the words 'mail', 'letter'
or 'correspondence' but not any of the words 'email', 'mailman'
'mailer', 'letterbox' etc."
<li><em>Search and Replace.</em> A regexp can be used to replace a
pattern with a piece of text, for example replace all occurrences of
'&' with '\&amp;' except where the '&' is already followed by
'amp;'.
<li><em>String Splitting.</em> A regexp can be used to identify
where a string should be split into its component fields, e.g.
splitting tab delimited strings.
</ol>
We present a very brief introduction to regexps, a description of
Qt's regexp language, some code examples, and finally the function
documentation. QRegExp is modelled on Perl's regexp engine and fully
supports Unicode. QRegExp may also be used in the weaker 'wildcard'
(globbing) mode which works in a similar way to command shells. A
good text on regexps is <i>Mastering Regular Expressions: Powerful
Techniques for Perl and Other Tools</i> by Jeffrey E. Friedl, ISBN
1565922573.
Experienced regexp users may prefer to skip the introduction and
go directly to the relevant information:
@@ -470,2685 +476,2685 @@
to match the Perl regex <b>ro+?m</b> requires:
\code
QRegExp rx( "ro+m" );
rx.setMinimal( TRUE );
\endcode
The equivalent of Perl's <tt>/i</tt> option is
setCaseSensitive(FALSE).
Perl's <tt>/g</tt> option can be emulated using a
<a href="#cap_in_a_loop">loop</a>.
In QRegExp <b>.</b> matches any character, therefore all QRegExp
regexps have the equivalent of Perl's <tt>/s</tt> option. QRegExp
does not have an equivalent to Perl's <tt>/m</tt> option, but this
can be emulated in various ways for example by splitting the input
into lines or by looping with a regexp that searches for newlines.
Because QRegExp is string oriented there are no \A, \Z or \z
assertions. The \G assertion is not supported but can be emulated in
a loop.
Perl's $& is cap(0) or capturedTexts()[0]. There are no QRegExp
equivalents for $`, $' or $+. $1, $2 etc correspond to
cap(1) or capturedTexts()[1], cap(2) or capturedTexts()[2], etc.
To substitute a pattern use QString::replace().
Perl's extended <tt>/x</tt> syntax is not supported, nor are regexp
comments (?#comment) or directives, e.g. (?i).
Both zero-width positive and zero-width negative lookahead
assertions (?=pattern) and (?!pattern) are supported with the same
syntax as Perl. Perl's lookbehind assertions, "independent"
subexpressions and conditional expressions are not supported.
Non-capturing parenthesis are also supported, with the same
(?:pattern) syntax.
See QStringList::split() and QStringList::join() for equivalents to
Perl's split and join functions.
Note: because C++ transforms \\'s they must be written \e twice in
code, e.g. <b>\\</b><b>b</b> must be written <b>\\</b><b>\\</b><b>b</b>.
<a name="code-examples"><b>Code Examples</b></a>
\code
- QRegExp rx( "^\\d\\d?$" ); // Match integers 0 to 99
- rx.search( "123" ); // Returns -1 (no match)
- rx.search( "-6" ); // Returns -1 (no match)
- rx.search( "6" ); // Returns 0 (matched as position 0)
+ QRegExp rx( "^\\d\\d?$" ); // Match integers 0 to 99
+ rx.search( "123" ); // Returns -1 (no match)
+ rx.search( "-6" ); // Returns -1 (no match)
+ rx.search( "6" ); // Returns 0 (matched as position 0)
\endcode
The third string matches '<u>6</u>'. This is a simple validation
regexp for integers in the range 0 to 99.
\code
- QRegExp rx( "^\\S+$" ); // Match strings which have no whitespace
- rx.search( "Hello world" ); // Returns -1 (no match)
- rx.search( "This_is-OK" ); // Returns 0 (matched at position 0)
+ QRegExp rx( "^\\S+$" ); // Match strings which have no whitespace
+ rx.search( "Hello world" ); // Returns -1 (no match)
+ rx.search( "This_is-OK" ); // Returns 0 (matched at position 0)
\endcode
The second string matches '<u>This_is-OK</u>'. We've used the
character set abbreviation '\S' (non-whitespace) and the anchors to
match strings which contain no whitespace.
In the following example we match strings containing 'mail' or
'letter' or 'correspondence' but only match whole words i.e. not
'email'
\code
QRegExp rx( "\\b(mail|letter|correspondence)\\b" );
- rx.search( "I sent you an email" ); // Returns -1 (no match)
+ rx.search( "I sent you an email" ); // Returns -1 (no match)
rx.search( "Please write the letter" ); // Returns 17 (matched at position 17)
\endcode
The second string matches "Please write the <u>letter</u>". The word
'letter' is also captured (because of the parenthesis). We can see
what text we've captured like this:
\code
QString captured = rx.cap( 1 ); // captured contains "letter"
\endcode
This will capture the text from the first set of capturing
parenthesis (counting capturing left parenthesis from left to
right). The parenthesis are counted from 1 since cap( 0 ) is the
whole matched regexp (equivalent to '&' in most regexp engines).
\code
- QRegExp rx( "&(?!amp;)" ); // Match ampersands but not &amp;
+ QRegExp rx( "&(?!amp;)" ); // Match ampersands but not &amp;
QString line1 = "This & that";
line1.replace( rx, "&amp;" );
// line1 == "This &amp; that"
QString line2 = "His &amp; hers & theirs";
line2.replace( rx, "&amp;" );
// line2 == "His &amp; hers &amp; theirs"
\endcode
Here we've passed the QRegExp to QString's replace() function to
replace the matched text with new text.
\code
QString str = "One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?";
- QRegExp rx( "\\b(Eric|Eirik)\\b" ); // Match Eric or Eirik
+ QRegExp rx( "\\b(Eric|Eirik)\\b" ); // Match Eric or Eirik
int pos = 0; // Where we are in the string
int count = 0; // How many Eric and Eirik's we've counted
while ( pos >= 0 ) {
- pos = rx.search( str, pos );
- if ( pos >= 0 ) {
- pos++; // Move along in str
- count++; // Count our Eric or Eirik
- }
+ pos = rx.search( str, pos );
+ if ( pos >= 0 ) {
+ pos++; // Move along in str
+ count++; // Count our Eric or Eirik
+ }
}
\endcode
We've used the search() function to repeatedly match the regexp in
the string. Note that instead of moving forward by one character at
a time <tt>pos++</tt> we could have written <tt>pos +=
rx.matchedLength()</tt> to skip over the already matched string. The
count will equal 3, matching 'One <u>Eric</u> another <u>Eirik</u>,
and an Ericsson. How many Eiriks, <u>Eric</u>?'; it doesn't match
'Ericsson' or 'Eiriks' because they are not bounded by non-word
boundaries.
One common use of regexps is to split lines of delimited data into
their component fields.
\code
str = "Trolltech AS\twww.trolltech.com\tNorway";
QString company, web, country;
rx.setPattern( "^([^\t]+)\t([^\t]+)\t([^\t]+)$" );
if ( rx.search( str ) != -1 ) {
- company = rx.cap( 1 );
- web = rx.cap( 2 );
- country = rx.cap( 3 );
+ company = rx.cap( 1 );
+ web = rx.cap( 2 );
+ country = rx.cap( 3 );
}
\endcode
In this example our input lines have the format company name, web
address and country. Unfortunately the regexp is rather long and not
very versatile -- the code will break if we add any more fields. A
simpler and better solution is to look for the separator, '\t' in
this case, and take the surrounding text. The QStringList split()
function can take a separator string or regexp as an argument and
split a string accordingly.
\code
QStringList field = QStringList::split( "\t", str );
\endcode
Here field[0] is the company, field[1] the web address and so on.
To immitate the matching of a shell we can use wildcard mode.
\code
- QRegExp rx( "*.html" ); // Invalid regexp: * doesn't quantify anything
- rx.setWildcard( TRUE ); // Now its a valid wildcard regexp
- rx.search( "index.html" ); // Returns 0 (matched at position 0)
- rx.search( "default.htm" ); // Returns -1 (no match)
- rx.search( "readme.txt" ); // Returns -1 (no match)
+ QRegExp rx( "*.html" ); // Invalid regexp: * doesn't quantify anything
+ rx.setWildcard( TRUE ); // Now its a valid wildcard regexp
+ rx.search( "index.html" ); // Returns 0 (matched at position 0)
+ rx.search( "default.htm" ); // Returns -1 (no match)
+ rx.search( "readme.txt" ); // Returns -1 (no match)
\endcode
Wildcard matching can be convenient because of its simplicity, but
any wildcard regex can be defined using full regexps, e.g.
<b>.*\.html$</b>. Notice that we can't match both \c .html and \c
.htm files with a wildcard unless we use <b>*.htm*</b> which will
also match 'test.html.bak'. A full regexp gives us the precision we
need, <b>.*\.html?$</b>.
QRegExp can match case insensitively using setCaseSensitive(), and
can use non-greedy matching, see setMinimal(). By default QRegExp
uses full regexps but this can be changed with setWildcard().
Searching can be forward with search() or backward with searchRev().
Captured text can be accessed using capturedTexts() which returns a
string list of all captured strings, or using cap() which returns
the captured string for the given index. The pos() function takes a
match index and returns the position in the string where the match
was made (or -1 if there was no match).
\sa QRegExpValidator QString QStringList
<a name="member-function-documentation"/>
*/
static const int NumBadChars = 128;
#define BadChar( ch ) ( (ch).cell() % NumBadChars )
static const int NoOccurrence = INT_MAX;
static const int EmptyCapture = INT_MAX;
static const int InftyLen = INT_MAX;
static const int InftyRep = 1000;
static const int EOS = -1;
#ifndef QT_NO_REGEXP_OPTIM
static int engCount = 0;
static QArray<int> *noOccurrences = 0;
static QArray<int> *firstOccurrenceAtZero = 0;
#endif
/*
Merges two QArrays of ints and puts the result into the first one.
*/
static void mergeInto( QArray<int> *a, const QArray<int>& b )
{
int asize = a->size();
int bsize = b.size();
if ( asize == 0 ) {
- *a = b.copy();
+ *a = b.copy();
#ifndef QT_NO_REGEXP_OPTIM
} else if ( bsize == 1 && (*a)[asize - 1] < b[0] ) {
- a->resize( asize + 1 );
- (*a)[asize] = b[0];
+ a->resize( asize + 1 );
+ (*a)[asize] = b[0];
#endif
} else if ( bsize >= 1 ) {
- int csize = asize + bsize;
- QArray<int> c( csize );
- int i = 0, j = 0, k = 0;
- while ( i < asize ) {
- if ( j < bsize ) {
- if ( (*a)[i] == b[j] ) {
- i++;
- csize--;
- } else if ( (*a)[i] < b[j] ) {
- c[k++] = (*a)[i++];
- } else {
- c[k++] = b[j++];
- }
- } else {
- memcpy( c.data() + k, (*a).data() + i,
- (asize - i) * sizeof(int) );
- break;
- }
- }
- c.resize( csize );
- if ( j < bsize )
- memcpy( c.data() + k, b.data() + j, (bsize - j) * sizeof(int) );
- *a = c;
+ int csize = asize + bsize;
+ QArray<int> c( csize );
+ int i = 0, j = 0, k = 0;
+ while ( i < asize ) {
+ if ( j < bsize ) {
+ if ( (*a)[i] == b[j] ) {
+ i++;
+ csize--;
+ } else if ( (*a)[i] < b[j] ) {
+ c[k++] = (*a)[i++];
+ } else {
+ c[k++] = b[j++];
+ }
+ } else {
+ memcpy( c.data() + k, (*a).data() + i,
+ (asize - i) * sizeof(int) );
+ break;
+ }
+ }
+ c.resize( csize );
+ if ( j < bsize )
+ memcpy( c.data() + k, b.data() + j, (bsize - j) * sizeof(int) );
+ *a = c;
}
}
/*
Merges two disjoint QMaps of (int, int) pairs and puts the result into the
first one.
*/
static void mergeInto( QMap<int, int> *a, const QMap<int, int>& b )
{
QMap<int, int>::ConstIterator it;
for ( it = b.begin(); it != b.end(); ++it )
- a->insert( it.key(), *it );
+ a->insert( it.key(), *it );
}
/*
Returns the value associated to key k in QMap m of (int, int) pairs, or 0 if
no such value is explicitly present.
*/
static int at( const QMap<int, int>& m, int k )
{
QMap<int, int>::ConstIterator it = m.find( k );
if ( it == m.end() )
- return 0;
+ return 0;
else
- return *it;
+ return *it;
}
#ifndef QT_NO_REGEXP_WILDCARD
/*
Translates a wildcard pattern to an equivalent regular expression pattern
(e.g., *.cpp to .*\.cpp).
*/
static QString wc2rx( const QString& wc )
{
int wclen = wc.length();
QString rx = QString::fromLatin1( "" );
int i = 0;
while ( i < wclen ) {
- QChar c = wc[i++];
- switch ( c.unicode() ) {
- case '*':
- rx += QString::fromLatin1( ".*" );
- break;
- case '?':
- rx += QChar( '.' );
- break;
- case '$':
- case '(':
- case ')':
- case '+':
- case '.':
- case '\\':
- case '^':
- case '{':
- case '|':
- case '}':
- rx += QChar( '\\' );
- rx += c;
- break;
- case '[':
- rx += c;
- if ( wc[i] == QChar('^') )
- rx += wc[i++];
- if ( i < wclen ) {
- if ( rx[i] == ']' )
- rx += wc[i++];
- while ( i < wclen && wc[i] != QChar(']') ) {
- if ( wc[i] == '\\' )
- rx += QChar( '\\' );
- rx += wc[i++];
- }
- }
- break;
- default:
- rx += c;
- }
+ QChar c = wc[i++];
+ switch ( c.unicode() ) {
+ case '*':
+ rx += QString::fromLatin1( ".*" );
+ break;
+ case '?':
+ rx += QChar( '.' );
+ break;
+ case '$':
+ case '(':
+ case ')':
+ case '+':
+ case '.':
+ case '\\':
+ case '^':
+ case '{':
+ case '|':
+ case '}':
+ rx += QChar( '\\' );
+ rx += c;
+ break;
+ case '[':
+ rx += c;
+ if ( wc[i] == QChar('^') )
+ rx += wc[i++];
+ if ( i < wclen ) {
+ if ( rx[i] == ']' )
+ rx += wc[i++];
+ while ( i < wclen && wc[i] != QChar(']') ) {
+ if ( wc[i] == '\\' )
+ rx += QChar( '\\' );
+ rx += wc[i++];
+ }
+ }
+ break;
+ default:
+ rx += c;
+ }
}
return rx;
}
#endif
/*
The class QRegExpEngine encapsulates a modified nondeterministic finite
automaton (NFA).
*/
class QRegExpEngine : public QShared
{
public:
#ifndef QT_NO_REGEXP_CCLASS
/*
The class CharClass represents a set of characters, such as can be found
in regular expressions (e.g., [a-z] denotes the set {a, b, ..., z}).
*/
class CharClass
{
public:
- CharClass();
- CharClass( const CharClass& cc ) { operator=( cc ); }
+ CharClass();
+ CharClass( const CharClass& cc ) { operator=( cc ); }
- CharClass& operator=( const CharClass& cc );
+ CharClass& operator=( const CharClass& cc );
- void clear();
- bool negative() const { return n; }
- void setNegative( bool negative );
- void addCategories( int cats );
- void addRange( ushort from, ushort to );
- void addSingleton( ushort ch ) { addRange( ch, ch ); }
+ void clear();
+ bool negative() const { return n; }
+ void setNegative( bool negative );
+ void addCategories( int cats );
+ void addRange( ushort from, ushort to );
+ void addSingleton( ushort ch ) { addRange( ch, ch ); }
- bool in( QChar ch ) const;
+ bool in( QChar ch ) const;
#ifndef QT_NO_REGEXP_OPTIM
- const QArray<int>& firstOccurrence() const { return occ1; }
+ const QArray<int>& firstOccurrence() const { return occ1; }
#endif
#if defined(QT_DEBUG)
- void dump() const;
+ void dump() const;
#endif
private:
- /*
- The struct Range represents a range of characters (e.g., [0-9] denotes
- range 48 to 57).
- */
- struct Range
- {
- ushort from; // 48
- ushort to; // 57
- };
-
- int c; // character classes
- QArray<Range> r; // character ranges
- bool n; // negative?
+ /*
+ The struct Range represents a range of characters (e.g., [0-9] denotes
+ range 48 to 57).
+ */
+ struct Range
+ {
+ ushort from; // 48
+ ushort to; // 57
+ };
+
+ int c; // character classes
+ QArray<Range> r; // character ranges
+ bool n; // negative?
#ifndef QT_NO_REGEXP_OPTIM
- QArray<int> occ1; // first-occurrence array
+ QArray<int> occ1; // first-occurrence array
#endif
};
#else
struct CharClass
{
- int x; // dummy
+ int x; // dummy
#ifndef QT_NO_REGEXP_OPTIM
- const QArray<int>& firstOccurrence() const {
- return *firstOccurrenceAtZero;
- }
+ const QArray<int>& firstOccurrence() const {
+ return *firstOccurrenceAtZero;
+ }
#endif
};
#endif
QRegExpEngine( bool caseSensitive ) { setup( caseSensitive ); }
QRegExpEngine( const QString& rx, bool caseSensitive );
#ifndef QT_NO_REGEXP_OPTIM
~QRegExpEngine();
#endif
bool isValid() const { return valid; }
bool caseSensitive() const { return cs; }
int numCaptures() const { return realncap; }
QArray<int> match( const QString& str, int pos, bool minimal,
- bool oneTest );
+ bool oneTest );
int matchedLength() const { return mmMatchedLen; }
int createState( QChar ch );
int createState( const CharClass& cc );
#ifndef QT_NO_REGEXP_BACKREF
int createState( int bref );
#endif
void addCatTransitions( const QArray<int>& from, const QArray<int>& to );
#ifndef QT_NO_REGEXP_CAPTURE
void addPlusTransitions( const QArray<int>& from, const QArray<int>& to,
- int atom );
+ int atom );
#endif
#ifndef QT_NO_REGEXP_ANCHOR_ALT
int anchorAlternation( int a, int b );
int anchorConcatenation( int a, int b );
#else
int anchorAlternation( int a, int b ) { return a & b; }
int anchorConcatenation( int a, int b ) { return a | b; }
#endif
void addAnchors( int from, int to, int a );
#ifndef QT_NO_REGEXP_OPTIM
void setupGoodStringHeuristic( int earlyStart, int lateStart,
- const QString& str );
+ const QString& str );
void setupBadCharHeuristic( int minLen, const QArray<int>& firstOcc );
void heuristicallyChooseHeuristic();
#endif
#if defined(QT_DEBUG)
void dump() const;
#endif
private:
enum { CharClassBit = 0x10000, BackRefBit = 0x20000 };
/*
The struct State represents one state in a modified NFA. The input
characters matched are stored in the state instead of on the transitions,
something possible for an automaton constructed from a regular expression.
*/
struct State
{
#ifndef QT_NO_REGEXP_CAPTURE
- int atom; // which atom does this state belong to?
+ int atom; // which atom does this state belong to?
#endif
- int match; // what does it match? (see CharClassBit and BackRefBit)
- QArray<int> outs; // out-transitions
- QMap<int, int> *reenter; // atoms reentered when transiting out
- QMap<int, int> *anchors; // anchors met when transiting out
+ int match; // what does it match? (see CharClassBit and BackRefBit)
+ QArray<int> outs; // out-transitions
+ QMap<int, int> *reenter; // atoms reentered when transiting out
+ QMap<int, int> *anchors; // anchors met when transiting out
#ifndef QT_NO_REGEXP_CAPTURE
- State( int a, int m )
- : atom( a ), match( m ), reenter( 0 ), anchors( 0 ) { }
+ State( int a, int m )
+ : atom( a ), match( m ), reenter( 0 ), anchors( 0 ) { }
#else
- State( int m )
- : match( m ), reenter( 0 ), anchors( 0 ) { }
+ State( int m )
+ : match( m ), reenter( 0 ), anchors( 0 ) { }
#endif
- ~State() { delete reenter; delete anchors; }
+ ~State() { delete reenter; delete anchors; }
};
#ifndef QT_NO_REGEXP_LOOKAHEAD
/*
The struct Lookahead represents a lookahead a la Perl (e.g., (?=foo) and
(?!bar)).
*/
struct Lookahead
{
- QRegExpEngine *eng; // NFA representing the embedded regular expression
- bool neg; // negative lookahead?
+ QRegExpEngine *eng; // NFA representing the embedded regular expression
+ bool neg; // negative lookahead?
- Lookahead( QRegExpEngine *eng0, bool neg0 )
- : eng( eng0 ), neg( neg0 ) { }
- ~Lookahead() { delete eng; }
+ Lookahead( QRegExpEngine *eng0, bool neg0 )
+ : eng( eng0 ), neg( neg0 ) { }
+ ~Lookahead() { delete eng; }
};
#endif
#ifndef QT_NO_REGEXP_CAPTURE
/*
The struct Atom represents one node in the hierarchy of regular expression
atoms.
*/
struct Atom
{
- int parent; // index of parent in array of atoms
- int capture; // index of capture, from 1 to ncap
+ int parent; // index of parent in array of atoms
+ int capture; // index of capture, from 1 to ncap
};
#endif
#ifndef QT_NO_REGEXP_ANCHOR_ALT
/*
The struct AnchorAlternation represents a pair of anchors with OR
semantics.
*/
struct AnchorAlternation
{
- int a; // this anchor...
- int b; // ...or this one
+ int a; // this anchor...
+ int b; // ...or this one
};
#endif
enum { InitialState = 0, FinalState = 1 };
void setup( bool caseSensitive );
int setupState( int match );
/*
Let's hope that 13 lookaheads and 14 back-references are enough.
*/
enum { MaxLookaheads = 13, MaxBackRefs = 14 };
enum { Anchor_Dollar = 0x00000001, Anchor_Caret = 0x00000002,
- Anchor_Word = 0x00000004, Anchor_NonWord = 0x00000008,
- Anchor_FirstLookahead = 0x00000010,
- Anchor_BackRef1Empty = Anchor_FirstLookahead << MaxLookaheads,
- Anchor_BackRef0Empty = Anchor_BackRef1Empty >> 1,
- Anchor_Alternation = Anchor_BackRef1Empty << MaxBackRefs,
-
- Anchor_LookaheadMask = ( Anchor_FirstLookahead - 1 ) ^
- ( (Anchor_FirstLookahead << MaxLookaheads) - 1 ) };
+ Anchor_Word = 0x00000004, Anchor_NonWord = 0x00000008,
+ Anchor_FirstLookahead = 0x00000010,
+ Anchor_BackRef1Empty = Anchor_FirstLookahead << MaxLookaheads,
+ Anchor_BackRef0Empty = Anchor_BackRef1Empty >> 1,
+ Anchor_Alternation = Anchor_BackRef1Empty << MaxBackRefs,
+
+ Anchor_LookaheadMask = ( Anchor_FirstLookahead - 1 ) ^
+ ( (Anchor_FirstLookahead << MaxLookaheads) - 1 ) };
#ifndef QT_NO_REGEXP_CAPTURE
int startAtom( bool capture );
void finishAtom( int atom ) { cf = f[atom].parent; }
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
int addLookahead( QRegExpEngine *eng, bool negative );
#endif
#ifndef QT_NO_REGEXP_CAPTURE
bool isBetterCapture( const int *begin1, const int *end1, const int *begin2,
- const int *end2 );
+ const int *end2 );
#endif
bool testAnchor( int i, int a, const int *capBegin );
#ifndef QT_NO_REGEXP_OPTIM
bool goodStringMatch();
bool badCharMatch();
#else
bool bruteMatch();
#endif
bool matchHere();
QVector<State> s; // array of states
int ns; // number of states
#ifndef QT_NO_REGEXP_CAPTURE
QArray<Atom> f; // atom hierarchy
int nf; // number of atoms
int cf; // current atom
#endif
int realncap; // number of captures, seen from the outside
int ncap; // number of captures, seen from the inside
#ifndef QT_NO_REGEXP_CCLASS
QVector<CharClass> cl; // array of character classes
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
QVector<Lookahead> ahead; // array of lookaheads
#endif
#ifndef QT_NO_REGEXP_ANCHOR_ALT
QArray<AnchorAlternation> aa; // array of (a, b) pairs of anchors
#endif
#ifndef QT_NO_REGEXP_OPTIM
bool caretAnchored; // does the regexp start with ^?
#endif
bool valid; // is the regular expression valid?
bool cs; // case sensitive?
#ifndef QT_NO_REGEXP_BACKREF
int nbrefs; // number of back-references
#endif
#ifndef QT_NO_REGEXP_OPTIM
bool useGoodStringHeuristic; // use goodStringMatch? otherwise badCharMatch
int goodEarlyStart; // the index where goodStr can first occur in a match
int goodLateStart; // the index where goodStr can last occur in a match
QString goodStr; // the string that any match has to contain
int minl; // the minimum length of a match
QArray<int> occ1; // first-occurrence array
#endif
/*
The class Box is an abstraction for a regular expression fragment. It can
also be seen as one node in the syntax tree of a regular expression with
synthetized attributes.
It's interface is ugly for performance reasons.
*/
class Box
{
public:
- Box( QRegExpEngine *engine );
- Box( const Box& b ) { operator=( b ); }
+ Box( QRegExpEngine *engine );
+ Box( const Box& b ) { operator=( b ); }
- Box& operator=( const Box& b );
+ Box& operator=( const Box& b );
- void clear() { operator=(Box(eng)); }
- void set( QChar ch );
- void set( const CharClass& cc );
+ void clear() { operator=(Box(eng)); }
+ void set( QChar ch );
+ void set( const CharClass& cc );
#ifndef QT_NO_REGEXP_BACKREF
- void set( int bref );
+ void set( int bref );
#endif
- void cat( const Box& b );
- void orx( const Box& b );
- void plus( int atom );
- void opt();
- void catAnchor( int a );
+ void cat( const Box& b );
+ void orx( const Box& b );
+ void plus( int atom );
+ void opt();
+ void catAnchor( int a );
#ifndef QT_NO_REGEXP_OPTIM
- void setupHeuristics();
+ void setupHeuristics();
#endif
#if defined(QT_DEBUG)
- void dump() const;
+ void dump() const;
#endif
private:
- void addAnchorsToEngine( const Box& to ) const;
+ void addAnchorsToEngine( const Box& to ) const;
- QRegExpEngine *eng; // the automaton under construction
- QArray<int> ls; // the left states (firstpos)
- QArray<int> rs; // the right states (lastpos)
- QMap<int, int> lanchors; // the left anchors
- QMap<int, int> ranchors; // the right anchors
- int skipanchors; // the anchors to match if the box is skipped
+ QRegExpEngine *eng; // the automaton under construction
+ QArray<int> ls; // the left states (firstpos)
+ QArray<int> rs; // the right states (lastpos)
+ QMap<int, int> lanchors; // the left anchors
+ QMap<int, int> ranchors; // the right anchors
+ int skipanchors; // the anchors to match if the box is skipped
#ifndef QT_NO_REGEXP_OPTIM
- int earlyStart; // the index where str can first occur
- int lateStart; // the index where str can last occur
- QString str; // a string that has to occur in any match
- QString leftStr; // a string occurring at the left of this box
- QString rightStr; // a string occurring at the right of this box
- int maxl; // the maximum length of this box (possibly InftyLen)
+ int earlyStart; // the index where str can first occur
+ int lateStart; // the index where str can last occur
+ QString str; // a string that has to occur in any match
+ QString leftStr; // a string occurring at the left of this box
+ QString rightStr; // a string occurring at the right of this box
+ int maxl; // the maximum length of this box (possibly InftyLen)
#endif
- int minl; // the minimum length of this box
+ int minl; // the minimum length of this box
#ifndef QT_NO_REGEXP_OPTIM
- QArray<int> occ1; // first-occurrence array
+ QArray<int> occ1; // first-occurrence array
#endif
};
friend class Box;
/*
This is the lexical analyzer for regular expressions.
*/
enum { Tok_Eos, Tok_Dollar, Tok_LeftParen, Tok_MagicLeftParen,
- Tok_PosLookahead, Tok_NegLookahead, Tok_RightParen, Tok_CharClass,
- Tok_Caret, Tok_Quantifier, Tok_Bar, Tok_Word, Tok_NonWord,
- Tok_Char = 0x10000, Tok_BackRef = 0x20000 };
+ Tok_PosLookahead, Tok_NegLookahead, Tok_RightParen, Tok_CharClass,
+ Tok_Caret, Tok_Quantifier, Tok_Bar, Tok_Word, Tok_NonWord,
+ Tok_Char = 0x10000, Tok_BackRef = 0x20000 };
int getChar();
int getEscape();
#ifndef QT_NO_REGEXP_INTERVAL
int getRep( int def );
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
void skipChars( int n );
#endif
void startTokenizer( const QChar *rx, int len );
int getToken();
const QChar *yyIn; // a pointer to the input regular expression pattern
int yyPos0; // the position of yyTok in the input pattern
int yyPos; // the position of the next character to read
int yyLen; // the length of yyIn
int yyCh; // the last character read
CharClass *yyCharClass; // attribute for Tok_CharClass tokens
int yyMinRep; // attribute for Tok_Quantifier
int yyMaxRep; // ditto
bool yyError; // syntax error or overflow during parsing?
/*
This is the syntactic analyzer for regular expressions.
*/
int parse( const QChar *rx, int len );
void parseAtom( Box *box );
void parseFactor( Box *box );
void parseTerm( Box *box );
void parseExpression( Box *box );
int yyTok; // the last token read
bool yyMayCapture; // set this to FALSE to disable capturing
/*
This is the engine state during matching.
*/
const QString *mmStr; // a pointer to the input QString
const QChar *mmIn; // a pointer to the input string data
int mmPos; // the current position in the string
int mmLen; // the length of the input string
bool mmMinimal; // minimal matching?
QArray<int> mmCaptured; // an array of pairs (start, len)
QArray<int> mmCapturedNoMatch; // an array of pairs (-1, -1)
QArray<int> mmBigArray; // big QArray<int> array
int *mmInNextStack; // is state is mmNextStack?
int *mmCurStack; // stack of current states
int *mmNextStack; // stack of next states
int *mmCurCapBegin; // start of current states' captures
int *mmNextCapBegin; // start of next states' captures
int *mmCurCapEnd; // end of current states' captures
int *mmNextCapEnd; // end of next states' captures
int *mmTempCapBegin; // start of temporary captures
int *mmTempCapEnd; // end of temporary captures
int *mmCapBegin; // start of captures for a next state
int *mmCapEnd; // end of captures for a next state
int *mmSlideTab; // bump-along slide table for bad-character heuristic
int mmSlideTabSize; // size of slide table
#ifndef QT_NO_REGEXP_BACKREF
QIntDict<int> mmSleeping; // dictionary of back-reference sleepers
#endif
int mmMatchedLen; // length of match or of matched string for partial match
};
QRegExpEngine::QRegExpEngine( const QString& rx, bool caseSensitive )
#ifndef QT_NO_REGEXP_BACKREF
: mmSleeping( 101 )
#endif
{
setup( caseSensitive );
valid = ( parse(rx.unicode(), rx.length()) == (int) rx.length() );
}
#ifndef QT_NO_REGEXP_OPTIM
QRegExpEngine::~QRegExpEngine()
{
if ( --engCount == 0 ) {
- delete noOccurrences;
- noOccurrences = 0;
- delete firstOccurrenceAtZero;
- firstOccurrenceAtZero = 0;
+ delete noOccurrences;
+ noOccurrences = 0;
+ delete firstOccurrenceAtZero;
+ firstOccurrenceAtZero = 0;
}
}
#endif
/*
Tries to match in str and returns an array of (begin, length) pairs for
captured text. If there is no match, all pairs are (-1, -1).
*/
QArray<int> QRegExpEngine::match( const QString& str, int pos, bool minimal,
- bool oneTest )
+ bool oneTest )
{
mmStr = &str;
mmIn = str.unicode();
if ( mmIn == 0 )
- mmIn = &QChar::null;
+ mmIn = &QChar::null;
mmPos = pos;
mmLen = str.length();
mmMinimal = minimal;
mmMatchedLen = 0;
bool matched = FALSE;
if ( valid && mmPos >= 0 && mmPos <= mmLen ) {
#ifndef QT_NO_REGEXP_OPTIM
- if ( mmPos <= mmLen - minl ) {
- if ( caretAnchored || oneTest )
- matched = matchHere();
- else if ( useGoodStringHeuristic )
- matched = goodStringMatch();
- else
- matched = badCharMatch();
- }
+ if ( mmPos <= mmLen - minl ) {
+ if ( caretAnchored || oneTest )
+ matched = matchHere();
+ else if ( useGoodStringHeuristic )
+ matched = goodStringMatch();
+ else
+ matched = badCharMatch();
+ }
#else
- matched = oneTest ? matchHere() : bruteMatch();
+ matched = oneTest ? matchHere() : bruteMatch();
#endif
}
if ( matched ) {
- mmCaptured.detach();
- mmCaptured[0] = mmPos;
- mmCaptured[1] = mmMatchedLen;
- for ( int j = 0; j < realncap; j++ ) {
- int len = mmCapEnd[j] - mmCapBegin[j];
- mmCaptured[2 + 2 * j] = len > 0 ? mmPos + mmCapBegin[j] : 0;
- mmCaptured[2 + 2 * j + 1] = len;
- }
- return mmCaptured;
+ mmCaptured.detach();
+ mmCaptured[0] = mmPos;
+ mmCaptured[1] = mmMatchedLen;
+ for ( int j = 0; j < realncap; j++ ) {
+ int len = mmCapEnd[j] - mmCapBegin[j];
+ mmCaptured[2 + 2 * j] = len > 0 ? mmPos + mmCapBegin[j] : 0;
+ mmCaptured[2 + 2 * j + 1] = len;
+ }
+ return mmCaptured;
} else {
- return mmCapturedNoMatch;
+ return mmCapturedNoMatch;
}
}
/*
The three following functions add one state to the automaton and return the
number of the state.
*/
int QRegExpEngine::createState( QChar ch )
{
return setupState( ch.unicode() );
}
int QRegExpEngine::createState( const CharClass& cc )
{
#ifndef QT_NO_REGEXP_CCLASS
int n = cl.size();
cl.resize( n + 1 );
cl.insert( n, new CharClass(cc) );
return setupState( CharClassBit | n );
#else
Q_UNUSED( cc );
return setupState( CharClassBit );
#endif
}
#ifndef QT_NO_REGEXP_BACKREF
int QRegExpEngine::createState( int bref )
{
if ( bref > nbrefs ) {
- nbrefs = bref;
- if ( nbrefs > MaxBackRefs ) {
- yyError = TRUE;
- return 0;
- }
+ nbrefs = bref;
+ if ( nbrefs > MaxBackRefs ) {
+ yyError = TRUE;
+ return 0;
+ }
}
return setupState( BackRefBit | bref );
}
#endif
/*
The two following functions add a transition between all pairs of states
(i, j) where i is fond in from, and j is found in to.
Cat-transitions are distinguished from plus-transitions for capturing.
*/
void QRegExpEngine::addCatTransitions( const QArray<int>& from,
- const QArray<int>& to )
+ const QArray<int>& to )
{
for ( int i = 0; i < (int) from.size(); i++ ) {
- State *st = s[from[i]];
- mergeInto( &st->outs, to );
+ State *st = s[from[i]];
+ mergeInto( &st->outs, to );
}
}
#ifndef QT_NO_REGEXP_CAPTURE
void QRegExpEngine::addPlusTransitions( const QArray<int>& from,
- const QArray<int>& to, int atom )
+ const QArray<int>& to, int atom )
{
for ( int i = 0; i < (int) from.size(); i++ ) {
- State *st = s[from[i]];
- QArray<int> oldOuts = st->outs.copy();
- mergeInto( &st->outs, to );
- if ( f[atom].capture >= 0 ) {
- if ( st->reenter == 0 )
- st->reenter = new QMap<int, int>;
- for ( int j = 0; j < (int) to.size(); j++ ) {
- if ( !st->reenter->contains(to[j]) &&
- oldOuts.bsearch(to[j]) < 0 )
- st->reenter->insert( to[j], atom );
- }
- }
+ State *st = s[from[i]];
+ QArray<int> oldOuts = st->outs.copy();
+ mergeInto( &st->outs, to );
+ if ( f[atom].capture >= 0 ) {
+ if ( st->reenter == 0 )
+ st->reenter = new QMap<int, int>;
+ for ( int j = 0; j < (int) to.size(); j++ ) {
+ if ( !st->reenter->contains(to[j]) &&
+ oldOuts.bsearch(to[j]) < 0 )
+ st->reenter->insert( to[j], atom );
+ }
+ }
}
}
#endif
#ifndef QT_NO_REGEXP_ANCHOR_ALT
/*
Returns an anchor that means a OR b.
*/
int QRegExpEngine::anchorAlternation( int a, int b )
{
if ( ((a & b) == a || (a & b) == b) && ((a | b) & Anchor_Alternation) == 0 )
- return a & b;
+ return a & b;
int n = aa.size();
aa.resize( n + 1 );
aa[n].a = a;
aa[n].b = b;
return Anchor_Alternation | n;
}
/*
Returns an anchor that means a AND b.
*/
int QRegExpEngine::anchorConcatenation( int a, int b )
{
if ( ((a | b) & Anchor_Alternation) == 0 )
- return a | b;
+ return a | b;
if ( (b & Anchor_Alternation) != 0 )
- qSwap( a, b );
+ qSwap( a, b );
int aprime = anchorConcatenation( aa[a ^ Anchor_Alternation].a, b );
int bprime = anchorConcatenation( aa[a ^ Anchor_Alternation].b, b );
return anchorAlternation( aprime, bprime );
}
#endif
/*
Adds anchor a on a transition caracterised by its from state and its to state.
*/
void QRegExpEngine::addAnchors( int from, int to, int a )
{
State *st = s[from];
if ( st->anchors == 0 )
- st->anchors = new QMap<int, int>;
+ st->anchors = new QMap<int, int>;
if ( st->anchors->contains(to) )
- a = anchorAlternation( (*st->anchors)[to], a );
+ a = anchorAlternation( (*st->anchors)[to], a );
st->anchors->insert( to, a );
}
#ifndef QT_NO_REGEXP_OPTIM
/*
The two following functions provide the engine with the information needed by
its matching heuristics.
*/
void QRegExpEngine::setupGoodStringHeuristic( int earlyStart, int lateStart,
- const QString& str )
+ const QString& str )
{
goodEarlyStart = earlyStart;
goodLateStart = lateStart;
goodStr = cs ? str : str.lower();
}
void QRegExpEngine::setupBadCharHeuristic( int minLen,
- const QArray<int>& firstOcc )
+ const QArray<int>& firstOcc )
{
minl = minLen;
occ1 = cs ? firstOcc : *firstOccurrenceAtZero;
}
/*
This function chooses between the good-string and the bad-character
heuristics. It computes two scores and chooses the heuristic with the highest
score.
Here are some common-sense constraints on the scores that should be respected
if the formulas are ever modified: (1) If goodStr is empty, the good-string
heuristic scores 0. (2) If the search is case insensitive, the good-string
heuristic should be used, unless it scores 0. (Case insensitivity
turns all entries of occ1 to 0.) (3) If (goodLateStart - goodEarlyStart) is
big, the good-string heuristic should score less.
*/
void QRegExpEngine::heuristicallyChooseHeuristic()
{
int i;
if ( minl == 0 )
- return;
+ return;
/*
Magic formula: The good string has to constitute a good proportion of the
minimum-length string, and appear at a more-or-less known index.
*/
int goodStringScore = ( 64 * goodStr.length() / minl ) -
- ( goodLateStart - goodEarlyStart );
+ ( goodLateStart - goodEarlyStart );
/*
Less magic formula: We pick a couple of characters at random, and check
whether they are good or bad.
*/
int badCharScore = 0;
int step = QMAX( 1, NumBadChars / 32 );
for ( i = 1; i < NumBadChars; i += step ) {
- if ( occ1[i] == NoOccurrence )
- badCharScore += minl;
- else
- badCharScore += occ1[i];
+ if ( occ1[i] == NoOccurrence )
+ badCharScore += minl;
+ else
+ badCharScore += occ1[i];
}
badCharScore /= minl;
useGoodStringHeuristic = ( goodStringScore > badCharScore );
}
#endif
#if defined(QT_DEBUG)
void QRegExpEngine::dump() const
{
int i, j;
- qDebug( "Case %ssensitive engine", cs ? "" : "in" );
- qDebug( " States" );
+ odebug << "Case " << (cs ? "" : "in") << "sensitive engine" << oendl;
+ odebug << " States" << oendl;
for ( i = 0; i < ns; i++ ) {
- qDebug( " %d%s", i,
- i == InitialState ? " (initial)" :
- i == FinalState ? " (final)" : "" );
+ odebug << " " << i
+ << (i == InitialState ? " (initial)" : i == FinalState ? " (final)" : "") << oendl;
+
#ifndef QT_NO_REGEXP_CAPTURE
- qDebug( " in atom %d", s[i]->atom );
+ odebug << " in atom " << s[i]->atom << oendl;
#endif
- int m = s[i]->match;
- if ( (m & CharClassBit) != 0 ) {
- qDebug( " match character class %d", m ^ CharClassBit );
+ int m = s[i]->match;
+ if ( (m & CharClassBit) != 0 ) {
+ odebug << " match character class " << (m ^ CharClassBit) << oendl;
#ifndef QT_NO_REGEXP_CCLASS
- cl[m ^ CharClassBit]->dump();
+ cl[m ^ CharClassBit]->dump();
#else
- qDebug( " negative character class" );
-#endif
- } else if ( (m & BackRefBit) != 0 ) {
- qDebug( " match back-reference %d", m ^ BackRefBit );
- } else if ( m >= 0x20 && m <= 0x7e ) {
- qDebug( " match 0x%.4x (%c)", m, m );
- } else {
- qDebug( " match 0x%.4x", m );
- }
- for ( j = 0; j < (int) s[i]->outs.size(); j++ ) {
- int next = s[i]->outs[j];
- qDebug( " -> %d", next );
- if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) )
- qDebug( " [reenter %d]", (*s[i]->reenter)[next] );
- if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 )
- qDebug( " [anchors 0x%.8x]", (*s[i]->anchors)[next] );
- }
+ odebug << " negative character class" << oendl;
+#endif
+ } else if ( (m & BackRefBit) != 0 ) {
+ odebug << " match back-reference " << (m ^ BackRefBit) << oendl;
+ } else if ( m >= 0x20 && m <= 0x7e ) {
+ odebug << " match " << QString().sprintf( "0x%.4x", m) << " (" << m << ")" << oendl;
+
+ } else {
+ odebug << " match " << QString().sprintf( "0x%.4x", m) << oendl;
+ }
+ for ( j = 0; j < (int) s[i]->outs.size(); j++ ) {
+ int next = s[i]->outs[j];
+ odebug << " -> " << next << oendl;
+ if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) )
+ odebug << " [reenter " << (*s[i]->reenter)[next] << "]" << oendl;
+ if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 )
+ odebug << " [anchors " << QString().sprintf( "0x%.8x]", (*s[i]->anchors)[next] ) << oendl;
+ }
}
#ifndef QT_NO_REGEXP_CAPTURE
if ( nf > 0 ) {
- qDebug( " Atom Parent Capture" );
- for ( i = 0; i < nf; i++ )
- qDebug( " %6d %6d %6d", i, f[i].parent, f[i].capture );
+ odebug << " Atom Parent Capture" << oendl;
+ for ( i = 0; i < nf; i++ )
+ odebug << QString().sprintf(" %6d %6d %6d", i, f[i].parent, f[i].capture ) << oendl;
}
#endif
#ifndef QT_NO_REGEXP_ANCHOR_ALT
for ( i = 0; i < (int) aa.size(); i++ )
- qDebug( " Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a,
- aa[i].b );
+ odebug << QString().sprintf(" Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, aa[i].b ) << oendl;
#endif
}
#endif
void QRegExpEngine::setup( bool caseSensitive )
{
#ifndef QT_NO_REGEXP_OPTIM
if ( engCount++ == 0 ) {
- noOccurrences = new QArray<int>( NumBadChars );
- firstOccurrenceAtZero = new QArray<int>( NumBadChars );
- noOccurrences->fill( NoOccurrence );
- firstOccurrenceAtZero->fill( 0 );
+ noOccurrences = new QArray<int>( NumBadChars );
+ firstOccurrenceAtZero = new QArray<int>( NumBadChars );
+ noOccurrences->fill( NoOccurrence );
+ firstOccurrenceAtZero->fill( 0 );
}
#endif
s.setAutoDelete( TRUE );
s.resize( 32 );
ns = 0;
#ifndef QT_NO_REGEXP_CAPTURE
f.resize( 32 );
nf = 0;
cf = -1;
#endif
realncap = 0;
ncap = 0;
#ifndef QT_NO_REGEXP_CCLASS
cl.setAutoDelete( TRUE );
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
ahead.setAutoDelete( TRUE );
#endif
#ifndef QT_NO_REGEXP_OPTIM
caretAnchored = TRUE;
#endif
valid = FALSE;
cs = caseSensitive;
#ifndef QT_NO_REGEXP_BACKREF
nbrefs = 0;
#endif
#ifndef QT_NO_REGEXP_OPTIM
useGoodStringHeuristic = FALSE;
minl = 0;
occ1 = *firstOccurrenceAtZero;
#endif
mmCapturedNoMatch.fill( -1, 2 );
}
int QRegExpEngine::setupState( int match )
{
if ( (ns & (ns + 1)) == 0 && ns + 1 >= (int) s.size() )
- s.resize( (ns + 1) << 1 );
+ s.resize( (ns + 1) << 1 );
#ifndef QT_NO_REGEXP_CAPTURE
s.insert( ns, new State(cf, match) );
#else
s.insert( ns, new State(match) );
#endif
return ns++;
}
#ifndef QT_NO_REGEXP_CAPTURE
/*
Functions startAtom() and finishAtom() should be called to delimit atoms.
When a state is created, it is assigned to the current atom. The information
is later used for capturing.
*/
int QRegExpEngine::startAtom( bool capture )
{
if ( (nf & (nf + 1)) == 0 && nf + 1 >= (int) f.size() )
- f.resize( (nf + 1) << 1 );
+ f.resize( (nf + 1) << 1 );
f[nf].parent = cf;
cf = nf++;
f[cf].capture = capture ? ncap++ : -1;
return cf;
}
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
/*
Creates a lookahead anchor.
*/
int QRegExpEngine::addLookahead( QRegExpEngine *eng, bool negative )
{
int n = ahead.size();
if ( n == MaxLookaheads ) {
- yyError = TRUE;
- return 0;
+ yyError = TRUE;
+ return 0;
}
ahead.resize( n + 1 );
ahead.insert( n, new Lookahead(eng, negative) );
return Anchor_FirstLookahead << n;
}
#endif
#ifndef QT_NO_REGEXP_CAPTURE
/*
We want the longest leftmost captures.
*/
bool QRegExpEngine::isBetterCapture( const int *begin1, const int *end1,
- const int *begin2, const int *end2 )
+ const int *begin2, const int *end2 )
{
for ( int i = 0; i < ncap; i++ ) {
- int delta = begin2[i] - begin1[i]; // it has to start early...
- if ( delta == 0 )
- delta = end1[i] - end2[i]; // ...and end late (like a party)
+ int delta = begin2[i] - begin1[i]; // it has to start early...
+ if ( delta == 0 )
+ delta = end1[i] - end2[i]; // ...and end late (like a party)
- if ( delta != 0 )
- return delta > 0;
+ if ( delta != 0 )
+ return delta > 0;
}
return FALSE;
}
#endif
/*
Returns TRUE if anchor a matches at position mmPos + i in the input string,
otherwise FALSE.
*/
bool QRegExpEngine::testAnchor( int i, int a, const int *capBegin )
{
int j;
#ifndef QT_NO_REGEXP_ANCHOR_ALT
if ( (a & Anchor_Alternation) != 0 ) {
- return testAnchor( i, aa[a ^ Anchor_Alternation].a, capBegin ) ||
- testAnchor( i, aa[a ^ Anchor_Alternation].b, capBegin );
+ return testAnchor( i, aa[a ^ Anchor_Alternation].a, capBegin ) ||
+ testAnchor( i, aa[a ^ Anchor_Alternation].b, capBegin );
}
#endif
if ( (a & Anchor_Caret) != 0 ) {
- if ( mmPos + i != 0 )
- return FALSE;
+ if ( mmPos + i != 0 )
+ return FALSE;
}
if ( (a & Anchor_Dollar) != 0 ) {
- if ( mmPos + i != mmLen )
- return FALSE;
+ if ( mmPos + i != mmLen )
+ return FALSE;
}
#ifndef QT_NO_REGEXP_ESCAPE
if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) {
- bool before = FALSE, after = FALSE;
- if ( mmPos + i != 0 )
- before = mmIn[mmPos + i - 1].isLetterOrNumber();
- if ( mmPos + i != mmLen )
- after = mmIn[mmPos + i].isLetterOrNumber();
- if ( (a & Anchor_Word) != 0 && (before == after) )
- return FALSE;
- if ( (a & Anchor_NonWord) != 0 && (before != after) )
- return FALSE;
+ bool before = FALSE, after = FALSE;
+ if ( mmPos + i != 0 )
+ before = mmIn[mmPos + i - 1].isLetterOrNumber();
+ if ( mmPos + i != mmLen )
+ after = mmIn[mmPos + i].isLetterOrNumber();
+ if ( (a & Anchor_Word) != 0 && (before == after) )
+ return FALSE;
+ if ( (a & Anchor_NonWord) != 0 && (before != after) )
+ return FALSE;
}
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
bool catchx = TRUE;
if ( (a & Anchor_LookaheadMask) != 0 ) {
- QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i,
- mmLen - mmPos - i );
- for ( j = 0; j < (int) ahead.size(); j++ ) {
- if ( (a & (Anchor_FirstLookahead << j)) != 0 ) {
- catchx = ( ahead[j]->eng->match(cstr.string(), 0, TRUE,
- TRUE)[0] == 0 );
- if ( catchx == ahead[j]->neg )
- return FALSE;
- }
- }
+ QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i,
+ mmLen - mmPos - i );
+ for ( j = 0; j < (int) ahead.size(); j++ ) {
+ if ( (a & (Anchor_FirstLookahead << j)) != 0 ) {
+ catchx = ( ahead[j]->eng->match(cstr.string(), 0, TRUE,
+ TRUE)[0] == 0 );
+ if ( catchx == ahead[j]->neg )
+ return FALSE;
+ }
+ }
}
#endif
#ifndef QT_NO_REGEXP_CAPTURE
#ifndef QT_NO_REGEXP_BACKREF
for ( j = 0; j < nbrefs; j++ ) {
- if ( (a & (Anchor_BackRef1Empty << j)) != 0 ) {
- if ( capBegin[j] != EmptyCapture )
- return FALSE;
- }
+ if ( (a & (Anchor_BackRef1Empty << j)) != 0 ) {
+ if ( capBegin[j] != EmptyCapture )
+ return FALSE;
+ }
}
#endif
#endif
return TRUE;
}
#ifndef QT_NO_REGEXP_OPTIM
/*
The three following functions are what Jeffrey Friedl would call transmissions
(or bump-alongs). Using one or the other should make no difference, except
in performance.
*/
bool QRegExpEngine::goodStringMatch()
{
int k = mmPos + goodEarlyStart;
while ( (k = mmStr->find(goodStr, k, cs)) != -1 ) {
- int from = k - goodLateStart;
- int to = k - goodEarlyStart;
- if ( from > mmPos )
- mmPos = from;
-
- while ( mmPos <= to ) {
- if ( matchHere() )
- return TRUE;
- mmPos++;
- }
- k++;
+ int from = k - goodLateStart;
+ int to = k - goodEarlyStart;
+ if ( from > mmPos )
+ mmPos = from;
+
+ while ( mmPos <= to ) {
+ if ( matchHere() )
+ return TRUE;
+ mmPos++;
+ }
+ k++;
}
return FALSE;
}
bool QRegExpEngine::badCharMatch()
{
int slideHead = 0;
int slideNext = 0;
int i;
int lastPos = mmLen - minl;
memset( mmSlideTab, 0, mmSlideTabSize * sizeof(int) );
/*
Set up the slide table, used for the bad-character heuristic, using
the table of first occurrence of each character.
*/
for ( i = 0; i < minl; i++ ) {
- int sk = occ1[BadChar(mmIn[mmPos + i])];
- if ( sk == NoOccurrence )
- sk = i + 1;
- if ( sk > 0 ) {
- int k = i + 1 - sk;
- if ( k < 0 ) {
- sk = i + 1;
- k = 0;
- }
- if ( sk > mmSlideTab[k] )
- mmSlideTab[k] = sk;
- }
+ int sk = occ1[BadChar(mmIn[mmPos + i])];
+ if ( sk == NoOccurrence )
+ sk = i + 1;
+ if ( sk > 0 ) {
+ int k = i + 1 - sk;
+ if ( k < 0 ) {
+ sk = i + 1;
+ k = 0;
+ }
+ if ( sk > mmSlideTab[k] )
+ mmSlideTab[k] = sk;
+ }
}
if ( mmPos > lastPos )
- return FALSE;
+ return FALSE;
while ( TRUE ) {
- if ( ++slideNext >= mmSlideTabSize )
- slideNext = 0;
- if ( mmSlideTab[slideHead] > 0 ) {
- if ( mmSlideTab[slideHead] - 1 > mmSlideTab[slideNext] )
- mmSlideTab[slideNext] = mmSlideTab[slideHead] - 1;
- mmSlideTab[slideHead] = 0;
- } else {
- if ( matchHere() )
- return TRUE;
- }
-
- if ( mmPos == lastPos )
- break;
-
- /*
- Update the slide table. This code has much in common with the
- initialization code.
- */
- int sk = occ1[BadChar(mmIn[mmPos + minl])];
- if ( sk == NoOccurrence ) {
- mmSlideTab[slideNext] = minl;
- } else if ( sk > 0 ) {
- int k = slideNext + minl - sk;
- if ( k >= mmSlideTabSize )
- k -= mmSlideTabSize;
- if ( sk > mmSlideTab[k] )
- mmSlideTab[k] = sk;
- }
- slideHead = slideNext;
- mmPos++;
+ if ( ++slideNext >= mmSlideTabSize )
+ slideNext = 0;
+ if ( mmSlideTab[slideHead] > 0 ) {
+ if ( mmSlideTab[slideHead] - 1 > mmSlideTab[slideNext] )
+ mmSlideTab[slideNext] = mmSlideTab[slideHead] - 1;
+ mmSlideTab[slideHead] = 0;
+ } else {
+ if ( matchHere() )
+ return TRUE;
+ }
+
+ if ( mmPos == lastPos )
+ break;
+
+ /*
+ Update the slide table. This code has much in common with the
+ initialization code.
+ */
+ int sk = occ1[BadChar(mmIn[mmPos + minl])];
+ if ( sk == NoOccurrence ) {
+ mmSlideTab[slideNext] = minl;
+ } else if ( sk > 0 ) {
+ int k = slideNext + minl - sk;
+ if ( k >= mmSlideTabSize )
+ k -= mmSlideTabSize;
+ if ( sk > mmSlideTab[k] )
+ mmSlideTab[k] = sk;
+ }
+ slideHead = slideNext;
+ mmPos++;
}
return FALSE;
}
#else
bool QRegExpEngine::bruteMatch()
{
while ( mmPos <= mmLen ) {
- if ( matchHere() )
- return TRUE;
- mmPos++;
+ if ( matchHere() )
+ return TRUE;
+ mmPos++;
}
return FALSE;
}
#endif
/*
Here's the core of the engine. It tries to do a match here and now.
*/
bool QRegExpEngine::matchHere()
{
int ncur = 1, nnext = 0;
int i = 0, j, k, m;
bool match = FALSE;
mmMatchedLen = -1;
mmCurStack[0] = InitialState;
#ifndef QT_NO_REGEXP_CAPTURE
if ( ncap > 0 ) {
- for ( j = 0; j < ncap; j++ ) {
- mmCurCapBegin[j] = EmptyCapture;
- mmCurCapEnd[j] = EmptyCapture;
- }
+ for ( j = 0; j < ncap; j++ ) {
+ mmCurCapBegin[j] = EmptyCapture;
+ mmCurCapEnd[j] = EmptyCapture;
+ }
}
#endif
#ifndef QT_NO_REGEXP_BACKREF
int *zzZ = 0;
while ( (ncur > 0 || mmSleeping.count() > 0) && i <= mmLen - mmPos &&
- !match )
+ !match )
#else
while ( ncur > 0 && i <= mmLen - mmPos && !match )
#endif
{
- int ch = ( i < mmLen - mmPos ) ? mmIn[mmPos + i].unicode() : 0;
- for ( j = 0; j < ncur; j++ ) {
- int cur = mmCurStack[j];
- State *scur = s[cur];
- QArray<int>& outs = scur->outs;
- for ( k = 0; k < (int) outs.size(); k++ ) {
- int next = outs[k];
- State *snext = s[next];
- bool in = TRUE;
+ int ch = ( i < mmLen - mmPos ) ? mmIn[mmPos + i].unicode() : 0;
+ for ( j = 0; j < ncur; j++ ) {
+ int cur = mmCurStack[j];
+ State *scur = s[cur];
+ QArray<int>& outs = scur->outs;
+ for ( k = 0; k < (int) outs.size(); k++ ) {
+ int next = outs[k];
+ State *snext = s[next];
+ bool in = TRUE;
#ifndef QT_NO_REGEXP_BACKREF
- int needSomeSleep = 0;
-#endif
-
- /*
- First, check if the anchors are anchored properly.
- */
- if ( scur->anchors != 0 ) {
- int a = at( *scur->anchors, next );
- if ( a != 0 && !testAnchor(i, a, mmCurCapBegin + j * ncap) )
- in = FALSE;
- }
- /*
- If indeed they are, check if the input character is correct
- for this transition.
- */
- if ( in ) {
- m = snext->match;
- if ( (m & (CharClassBit | BackRefBit)) == 0 ) {
- if ( cs )
- in = ( m == ch );
- else
- in = ( QChar(m).lower() == QChar(ch).lower() );
- } else if ( next == FinalState ) {
- mmMatchedLen = i;
- match = mmMinimal;
- in = TRUE;
- } else if ( (m & CharClassBit) != 0 ) {
+ int needSomeSleep = 0;
+#endif
+
+ /*
+ First, check if the anchors are anchored properly.
+ */
+ if ( scur->anchors != 0 ) {
+ int a = at( *scur->anchors, next );
+ if ( a != 0 && !testAnchor(i, a, mmCurCapBegin + j * ncap) )
+ in = FALSE;
+ }
+ /*
+ If indeed they are, check if the input character is correct
+ for this transition.
+ */
+ if ( in ) {
+ m = snext->match;
+ if ( (m & (CharClassBit | BackRefBit)) == 0 ) {
+ if ( cs )
+ in = ( m == ch );
+ else
+ in = ( QChar(m).lower() == QChar(ch).lower() );
+ } else if ( next == FinalState ) {
+ mmMatchedLen = i;
+ match = mmMinimal;
+ in = TRUE;
+ } else if ( (m & CharClassBit) != 0 ) {
#ifndef QT_NO_REGEXP_CCLASS
- const CharClass *cc = cl[m ^ CharClassBit];
- if ( cs )
- in = cc->in( ch );
- else if ( cc->negative() )
- in = cc->in( QChar(ch).lower() ) &&
- cc->in( QChar(ch).upper() );
- else
- in = cc->in( QChar(ch).lower() ) ||
- cc->in( QChar(ch).upper() );
+ const CharClass *cc = cl[m ^ CharClassBit];
+ if ( cs )
+ in = cc->in( ch );
+ else if ( cc->negative() )
+ in = cc->in( QChar(ch).lower() ) &&
+ cc->in( QChar(ch).upper() );
+ else
+ in = cc->in( QChar(ch).lower() ) ||
+ cc->in( QChar(ch).upper() );
#endif
#ifndef QT_NO_REGEXP_BACKREF
- } else { /* ( (m & BackRefBit) != 0 ) */
- int bref = m ^ BackRefBit;
- int ell = j * ncap + ( bref - 1 );
-
- in = bref <= ncap && mmCurCapBegin[ell] != EmptyCapture;
- if ( in ) {
- if ( cs )
- in = ( mmIn[mmPos + mmCurCapBegin[ell]]
- == QChar(ch) );
- else
- in = ( mmIn[mmPos + mmCurCapBegin[ell]].lower()
- == QChar(ch).lower() );
- }
-
- if ( in ) {
- int delta;
- if ( mmCurCapEnd[ell] == EmptyCapture )
- delta = i - mmCurCapBegin[ell];
- else
- delta = mmCurCapEnd[ell] - mmCurCapBegin[ell];
-
- in = ( delta <= mmLen - mmPos );
- if ( in && delta > 1 ) {
- int n;
- if ( cs ) {
- for ( n = 1; n < delta; n++ ) {
- if ( mmIn[mmPos +
- mmCurCapBegin[ell] + n] !=
- mmIn[mmPos + i + n] )
- break;
- }
- } else {
- for ( n = 1; n < delta; n++ ) {
- QChar a = mmIn[mmPos +
- mmCurCapBegin[ell] + n];
- QChar b = mmIn[mmPos + i + n];
- if ( a.lower() != b.lower() )
- break;
- }
- }
- in = ( n == delta );
- if ( in )
- needSomeSleep = delta - 1;
- }
- }
-#endif
- }
- }
-
- /*
- All is right. We must now update our data structures.
- */
- if ( in ) {
+ } else { /* ( (m & BackRefBit) != 0 ) */
+ int bref = m ^ BackRefBit;
+ int ell = j * ncap + ( bref - 1 );
+
+ in = bref <= ncap && mmCurCapBegin[ell] != EmptyCapture;
+ if ( in ) {
+ if ( cs )
+ in = ( mmIn[mmPos + mmCurCapBegin[ell]]
+ == QChar(ch) );
+ else
+ in = ( mmIn[mmPos + mmCurCapBegin[ell]].lower()
+ == QChar(ch).lower() );
+ }
+
+ if ( in ) {
+ int delta;
+ if ( mmCurCapEnd[ell] == EmptyCapture )
+ delta = i - mmCurCapBegin[ell];
+ else
+ delta = mmCurCapEnd[ell] - mmCurCapBegin[ell];
+
+ in = ( delta <= mmLen - mmPos );
+ if ( in && delta > 1 ) {
+ int n;
+ if ( cs ) {
+ for ( n = 1; n < delta; n++ ) {
+ if ( mmIn[mmPos +
+ mmCurCapBegin[ell] + n] !=
+ mmIn[mmPos + i + n] )
+ break;
+ }
+ } else {
+ for ( n = 1; n < delta; n++ ) {
+ QChar a = mmIn[mmPos +
+ mmCurCapBegin[ell] + n];
+ QChar b = mmIn[mmPos + i + n];
+ if ( a.lower() != b.lower() )
+ break;
+ }
+ }
+ in = ( n == delta );
+ if ( in )
+ needSomeSleep = delta - 1;
+ }
+ }
+#endif
+ }
+ }
+
+ /*
+ All is right. We must now update our data structures.
+ */
+ if ( in ) {
#ifndef QT_NO_REGEXP_CAPTURE
- int *capBegin, *capEnd;
-#endif
- /*
- If the next state was not encountered yet, all is fine.
- */
- if ( (m = mmInNextStack[next]) == -1 ) {
- m = nnext++;
- mmNextStack[m] = next;
- mmInNextStack[next] = m;
+ int *capBegin, *capEnd;
+#endif
+ /*
+ If the next state was not encountered yet, all is fine.
+ */
+ if ( (m = mmInNextStack[next]) == -1 ) {
+ m = nnext++;
+ mmNextStack[m] = next;
+ mmInNextStack[next] = m;
#ifndef QT_NO_REGEXP_CAPTURE
- capBegin = mmNextCapBegin + m * ncap;
- capEnd = mmNextCapEnd + m * ncap;
+ capBegin = mmNextCapBegin + m * ncap;
+ capEnd = mmNextCapEnd + m * ncap;
- /*
- Otherwise, we'll first maintain captures in temporary
- arrays, and decide at the end whether it's best to keep
- the previous capture zones or the new ones.
- */
- } else {
- capBegin = mmTempCapBegin;
- capEnd = mmTempCapEnd;
+ /*
+ Otherwise, we'll first maintain captures in temporary
+ arrays, and decide at the end whether it's best to keep
+ the previous capture zones or the new ones.
+ */
+ } else {
+ capBegin = mmTempCapBegin;
+ capEnd = mmTempCapEnd;
#endif
- }
+ }
#ifndef QT_NO_REGEXP_CAPTURE
- /*
- Updating the capture zones is much of a task.
- */
- if ( ncap > 0 ) {
- memcpy( capBegin, mmCurCapBegin + j * ncap,
- ncap * sizeof(int) );
- memcpy( capEnd, mmCurCapEnd + j * ncap,
- ncap * sizeof(int) );
- int c = scur->atom, n = snext->atom;
- int p = -1, q = -1;
- int cap;
-
- /*
- Lemma 1. For any x in the range [0..nf), we have
- f[x].parent < x.
-
- Proof. By looking at startAtom(), it is clear that
- cf < nf holds all the time, and thus that
- f[nf].parent < nf.
- */
-
- /*
- If we are reentering an atom, we empty all capture
- zones inside it.
- */
- if ( scur->reenter != 0 &&
- (q = at(*scur->reenter, next)) != 0 ) {
- QBitArray b;
- b.fill( FALSE, nf );
- b.setBit( q, TRUE );
- for ( int ell = q + 1; ell < nf; ell++ ) {
- if ( b.testBit(f[ell].parent) ) {
- b.setBit( ell, TRUE );
- cap = f[ell].capture;
- if ( cap >= 0 ) {
- capBegin[cap] = EmptyCapture;
- capEnd[cap] = EmptyCapture;
- }
- }
- }
- p = f[q].parent;
-
- /*
- Otherwise, close the capture zones we are leaving.
- We are leaving f[c].capture, f[f[c].parent].capture,
- f[f[f[c].parent].parent].capture, ..., until
- f[x].capture, with x such that f[x].parent is the
- youngest common ancestor for c and n.
-
- We go up along c's and n's ancestry until we find x.
- */
- } else {
- p = c;
- q = n;
- while ( p != q ) {
- if ( p > q ) {
- cap = f[p].capture;
- if ( cap >= 0 ) {
- if ( capBegin[cap] == i ) {
- capBegin[cap] = EmptyCapture;
- capEnd[cap] = EmptyCapture;
- } else {
- capEnd[cap] = i;
- }
- }
- p = f[p].parent;
- } else {
- q = f[q].parent;
- }
- }
- }
-
- /*
- In any case, we now open the capture zones we are
- entering. We work upwards from n until we reach p
- (the parent of the atom we reenter or the youngest
- common ancestor).
- */
- while ( n > p ) {
- cap = f[n].capture;
- if ( cap >= 0 ) {
- capBegin[cap] = i;
- capEnd[cap] = EmptyCapture;
- }
- n = f[n].parent;
- }
- /*
- If the next state was already in mmNextStack, we must
- choose carefully which capture zones we want to keep.
- */
- if ( capBegin == mmTempCapBegin &&
- isBetterCapture(capBegin, capEnd,
- mmNextCapBegin + m * ncap,
- mmNextCapEnd + m * ncap) ) {
- memcpy( mmNextCapBegin + m * ncap, capBegin,
- ncap * sizeof(int) );
- memcpy( mmNextCapEnd + m * ncap, capEnd,
- ncap * sizeof(int) );
- }
- }
+ /*
+ Updating the capture zones is much of a task.
+ */
+ if ( ncap > 0 ) {
+ memcpy( capBegin, mmCurCapBegin + j * ncap,
+ ncap * sizeof(int) );
+ memcpy( capEnd, mmCurCapEnd + j * ncap,
+ ncap * sizeof(int) );
+ int c = scur->atom, n = snext->atom;
+ int p = -1, q = -1;
+ int cap;
+
+ /*
+ Lemma 1. For any x in the range [0..nf), we have
+ f[x].parent < x.
+
+ Proof. By looking at startAtom(), it is clear that
+ cf < nf holds all the time, and thus that
+ f[nf].parent < nf.
+ */
+
+ /*
+ If we are reentering an atom, we empty all capture
+ zones inside it.
+ */
+ if ( scur->reenter != 0 &&
+ (q = at(*scur->reenter, next)) != 0 ) {
+ QBitArray b;
+ b.fill( FALSE, nf );
+ b.setBit( q, TRUE );
+ for ( int ell = q + 1; ell < nf; ell++ ) {
+ if ( b.testBit(f[ell].parent) ) {
+ b.setBit( ell, TRUE );
+ cap = f[ell].capture;
+ if ( cap >= 0 ) {
+ capBegin[cap] = EmptyCapture;
+ capEnd[cap] = EmptyCapture;
+ }
+ }
+ }
+ p = f[q].parent;
+
+ /*
+ Otherwise, close the capture zones we are leaving.
+ We are leaving f[c].capture, f[f[c].parent].capture,
+ f[f[f[c].parent].parent].capture, ..., until
+ f[x].capture, with x such that f[x].parent is the
+ youngest common ancestor for c and n.
+
+ We go up along c's and n's ancestry until we find x.
+ */
+ } else {
+ p = c;
+ q = n;
+ while ( p != q ) {
+ if ( p > q ) {
+ cap = f[p].capture;
+ if ( cap >= 0 ) {
+ if ( capBegin[cap] == i ) {
+ capBegin[cap] = EmptyCapture;
+ capEnd[cap] = EmptyCapture;
+ } else {
+ capEnd[cap] = i;
+ }
+ }
+ p = f[p].parent;
+ } else {
+ q = f[q].parent;
+ }
+ }
+ }
+
+ /*
+ In any case, we now open the capture zones we are
+ entering. We work upwards from n until we reach p
+ (the parent of the atom we reenter or the youngest
+ common ancestor).
+ */
+ while ( n > p ) {
+ cap = f[n].capture;
+ if ( cap >= 0 ) {
+ capBegin[cap] = i;
+ capEnd[cap] = EmptyCapture;
+ }
+ n = f[n].parent;
+ }
+ /*
+ If the next state was already in mmNextStack, we must
+ choose carefully which capture zones we want to keep.
+ */
+ if ( capBegin == mmTempCapBegin &&
+ isBetterCapture(capBegin, capEnd,
+ mmNextCapBegin + m * ncap,
+ mmNextCapEnd + m * ncap) ) {
+ memcpy( mmNextCapBegin + m * ncap, capBegin,
+ ncap * sizeof(int) );
+ memcpy( mmNextCapEnd + m * ncap, capEnd,
+ ncap * sizeof(int) );
+ }
+ }
#ifndef QT_NO_REGEXP_BACKREF
- /*
- We are done with updating the capture zones. It's now
- time to put the next state to sleep, if it needs to, and
- to remove it from mmNextStack.
- */
- if ( needSomeSleep > 0 ) {
- zzZ = new int[1 + 2 * ncap];
- zzZ[0] = next;
- if ( ncap > 0 ) {
- memcpy( zzZ + 1, capBegin, ncap * sizeof(int) );
- memcpy( zzZ + 1 + ncap, capEnd,
- ncap * sizeof(int) );
- }
- mmInNextStack[mmNextStack[--nnext]] = -1;
- mmSleeping.insert( i + needSomeSleep, zzZ );
- }
-#endif
-#endif
- }
- }
- }
+ /*
+ We are done with updating the capture zones. It's now
+ time to put the next state to sleep, if it needs to, and
+ to remove it from mmNextStack.
+ */
+ if ( needSomeSleep > 0 ) {
+ zzZ = new int[1 + 2 * ncap];
+ zzZ[0] = next;
+ if ( ncap > 0 ) {
+ memcpy( zzZ + 1, capBegin, ncap * sizeof(int) );
+ memcpy( zzZ + 1 + ncap, capEnd,
+ ncap * sizeof(int) );
+ }
+ mmInNextStack[mmNextStack[--nnext]] = -1;
+ mmSleeping.insert( i + needSomeSleep, zzZ );
+ }
+#endif
+#endif
+ }
+ }
+ }
#ifndef QT_NO_REGEXP_CAPTURE
- /*
- If we reached the final state, hurray! Copy the captured zone.
- */
- if ( ncap > 0 && (m = mmInNextStack[FinalState]) != -1 ) {
- memcpy( mmCapBegin, mmNextCapBegin + m * ncap, ncap * sizeof(int) );
- memcpy( mmCapEnd, mmNextCapEnd + m * ncap, ncap * sizeof(int) );
- }
+ /*
+ If we reached the final state, hurray! Copy the captured zone.
+ */
+ if ( ncap > 0 && (m = mmInNextStack[FinalState]) != -1 ) {
+ memcpy( mmCapBegin, mmNextCapBegin + m * ncap, ncap * sizeof(int) );
+ memcpy( mmCapEnd, mmNextCapEnd + m * ncap, ncap * sizeof(int) );
+ }
#ifndef QT_NO_REGEXP_BACKREF
- /*
- It's time to wake up the sleepers.
- */
- if ( mmSleeping.count() > 0 ) {
- while ( (zzZ = mmSleeping.take(i)) != 0 ) {
- int next = zzZ[0];
- int *capBegin = zzZ + 1;
- int *capEnd = zzZ + 1 + ncap;
- bool copyOver = TRUE;
-
- if ( (m = mmInNextStack[zzZ[0]]) == -1 ) {
- m = nnext++;
- mmNextStack[m] = next;
- mmInNextStack[next] = m;
- } else {
- copyOver = isBetterCapture( mmNextCapBegin + m * ncap,
- mmNextCapEnd + m * ncap,
- capBegin, capEnd );
- }
- if ( copyOver ) {
- memcpy( mmNextCapBegin + m * ncap, capBegin,
- ncap * sizeof(int) );
- memcpy( mmNextCapEnd + m * ncap, capEnd,
- ncap * sizeof(int) );
- }
- delete[] zzZ;
- }
- }
-#endif
-#endif
- for ( j = 0; j < nnext; j++ )
- mmInNextStack[mmNextStack[j]] = -1;
-
- qSwap( mmCurStack, mmNextStack );
+ /*
+ It's time to wake up the sleepers.
+ */
+ if ( mmSleeping.count() > 0 ) {
+ while ( (zzZ = mmSleeping.take(i)) != 0 ) {
+ int next = zzZ[0];
+ int *capBegin = zzZ + 1;
+ int *capEnd = zzZ + 1 + ncap;
+ bool copyOver = TRUE;
+
+ if ( (m = mmInNextStack[zzZ[0]]) == -1 ) {
+ m = nnext++;
+ mmNextStack[m] = next;
+ mmInNextStack[next] = m;
+ } else {
+ copyOver = isBetterCapture( mmNextCapBegin + m * ncap,
+ mmNextCapEnd + m * ncap,
+ capBegin, capEnd );
+ }
+ if ( copyOver ) {
+ memcpy( mmNextCapBegin + m * ncap, capBegin,
+ ncap * sizeof(int) );
+ memcpy( mmNextCapEnd + m * ncap, capEnd,
+ ncap * sizeof(int) );
+ }
+ delete[] zzZ;
+ }
+ }
+#endif
+#endif
+ for ( j = 0; j < nnext; j++ )
+ mmInNextStack[mmNextStack[j]] = -1;
+
+ qSwap( mmCurStack, mmNextStack );
#ifndef QT_NO_REGEXP_CAPTURE
- qSwap( mmCurCapBegin, mmNextCapBegin );
- qSwap( mmCurCapEnd, mmNextCapEnd );
+ qSwap( mmCurCapBegin, mmNextCapBegin );
+ qSwap( mmCurCapEnd, mmNextCapEnd );
#endif
- ncur = nnext;
- nnext = 0;
- i++;
+ ncur = nnext;
+ nnext = 0;
+ i++;
}
#ifndef QT_NO_REGEXP_BACKREF
/*
If minimal matching is enabled, we might have some sleepers left.
*/
while ( !mmSleeping.isEmpty() ) {
- zzZ = mmSleeping.take( *QIntDictIterator<int>(mmSleeping) );
- delete[] zzZ;
+ zzZ = mmSleeping.take( *QIntDictIterator<int>(mmSleeping) );
+ delete[] zzZ;
}
#endif
match = ( mmMatchedLen >= 0 );
if ( !match )
- mmMatchedLen = i - 1;
+ mmMatchedLen = i - 1;
return match;
}
#ifndef QT_NO_REGEXP_CCLASS
QRegExpEngine::CharClass::CharClass()
: c( 0 ), n( FALSE )
#ifndef QT_NO_REGEXP_OPTIM
, occ1( *noOccurrences )
#endif
{
}
QRegExpEngine::CharClass& QRegExpEngine::CharClass::operator=(
- const CharClass& cc )
+ const CharClass& cc )
{
c = cc.c;
r = cc.r.copy();
n = cc.n;
#ifndef QT_NO_REGEXP_OPTIM
occ1 = cc.occ1;
#endif
return *this;
}
void QRegExpEngine::CharClass::clear()
{
c = 0;
r.resize( 0 );
n = FALSE;
}
void QRegExpEngine::CharClass::setNegative( bool negative )
{
n = negative;
#ifndef QT_NO_REGEXP_OPTIM
occ1 = *firstOccurrenceAtZero;
#endif
}
void QRegExpEngine::CharClass::addCategories( int cats )
{
c |= cats;
#ifndef QT_NO_REGEXP_OPTIM
occ1 = *firstOccurrenceAtZero;
#endif
}
void QRegExpEngine::CharClass::addRange( ushort from, ushort to )
{
if ( from > to )
- qSwap( from, to );
+ qSwap( from, to );
int n = r.size();
r.resize( n + 1 );
r[n].from = from;
r[n].to = to;
#ifndef QT_NO_REGEXP_OPTIM
int i;
if ( to - from < NumBadChars ) {
- occ1.detach();
- if ( from % NumBadChars <= to % NumBadChars ) {
- for ( i = from % NumBadChars; i <= to % NumBadChars; i++ )
- occ1[i] = 0;
- } else {
- for ( i = 0; i <= to % NumBadChars; i++ )
- occ1[i] = 0;
- for ( i = from % NumBadChars; i < NumBadChars; i++ )
- occ1[i] = 0;
- }
+ occ1.detach();
+ if ( from % NumBadChars <= to % NumBadChars ) {
+ for ( i = from % NumBadChars; i <= to % NumBadChars; i++ )
+ occ1[i] = 0;
} else {
- occ1 = *firstOccurrenceAtZero;
+ for ( i = 0; i <= to % NumBadChars; i++ )
+ occ1[i] = 0;
+ for ( i = from % NumBadChars; i < NumBadChars; i++ )
+ occ1[i] = 0;
+ }
+ } else {
+ occ1 = *firstOccurrenceAtZero;
}
#endif
}
bool QRegExpEngine::CharClass::in( QChar ch ) const
{
#ifndef QT_NO_REGEXP_OPTIM
if ( occ1[BadChar(ch)] == NoOccurrence )
- return n;
+ return n;
#endif
if ( c != 0 && (c & (1 << (int) ch.category())) != 0 )
- return !n;
+ return !n;
for ( int i = 0; i < (int) r.size(); i++ ) {
- if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to )
- return !n;
+ if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to )
+ return !n;
}
return n;
}
#if defined(QT_DEBUG)
void QRegExpEngine::CharClass::dump() const
{
int i;
- qDebug( " %stive character class", n ? "nega" : "posi" );
+ odebug << " " << (n ? "nega" : "posi") << "tive character class" << oendl;
#ifndef QT_NO_REGEXP_CCLASS
if ( c != 0 )
- qDebug( " categories 0x%.8x", c );
+ odebug << QString().sprintf(" categories 0x%.8x", c ) << oendl;
#endif
for ( i = 0; i < (int) r.size(); i++ )
- qDebug( " 0x%.4x through 0x%.4x", r[i].from, r[i].to );
+ odebug << QString().sprintf(" 0x%.4x through 0x%.4x", r[i].from, r[i].to ) << oendl;
}
#endif
#endif
QRegExpEngine::Box::Box( QRegExpEngine *engine )
: eng( engine ), skipanchors( 0 )
#ifndef QT_NO_REGEXP_OPTIM
, earlyStart( 0 ), lateStart( 0 ), maxl( 0 ), occ1( *noOccurrences )
#endif
{
minl = 0;
}
QRegExpEngine::Box& QRegExpEngine::Box::operator=( const Box& b )
{
eng = b.eng;
ls = b.ls;
rs = b.rs;
lanchors = b.lanchors;
ranchors = b.ranchors;
skipanchors = b.skipanchors;
#ifndef QT_NO_REGEXP_OPTIM
earlyStart = b.earlyStart;
lateStart = b.lateStart;
str = b.str;
leftStr = b.leftStr;
rightStr = b.rightStr;
maxl = b.maxl;
occ1 = b.occ1;
#endif
minl = b.minl;
return *this;
}
void QRegExpEngine::Box::set( QChar ch )
{
ls.resize( 1 );
ls[0] = eng->createState( ch );
rs = ls;
rs.detach();
#ifndef QT_NO_REGEXP_OPTIM
str = ch;
leftStr = ch;
rightStr = ch;
maxl = 1;
occ1.detach();
occ1[BadChar(ch)] = 0;
#endif
minl = 1;
}
void QRegExpEngine::Box::set( const CharClass& cc )
{
ls.resize( 1 );
ls[0] = eng->createState( cc );
rs = ls;
rs.detach();
#ifndef QT_NO_REGEXP_OPTIM
maxl = 1;
occ1 = cc.firstOccurrence();
#endif
minl = 1;
}
#ifndef QT_NO_REGEXP_BACKREF
void QRegExpEngine::Box::set( int bref )
{
ls.resize( 1 );
ls[0] = eng->createState( bref );
rs = ls;
rs.detach();
if ( bref >= 1 && bref <= MaxBackRefs )
- skipanchors = Anchor_BackRef0Empty << bref;
+ skipanchors = Anchor_BackRef0Empty << bref;
#ifndef QT_NO_REGEXP_OPTIM
maxl = InftyLen;
#endif
minl = 0;
}
#endif
void QRegExpEngine::Box::cat( const Box& b )
{
eng->addCatTransitions( rs, b.ls );
addAnchorsToEngine( b );
if ( minl == 0 ) {
- mergeInto( &lanchors, b.lanchors );
- if ( skipanchors != 0 ) {
- for ( int i = 0; i < (int) b.ls.size(); i++ ) {
- int a = eng->anchorConcatenation( at(lanchors, b.ls[i]),
- skipanchors );
- lanchors.insert( b.ls[i], a );
- }
- }
- mergeInto( &ls, b.ls );
+ mergeInto( &lanchors, b.lanchors );
+ if ( skipanchors != 0 ) {
+ for ( int i = 0; i < (int) b.ls.size(); i++ ) {
+ int a = eng->anchorConcatenation( at(lanchors, b.ls[i]),
+ skipanchors );
+ lanchors.insert( b.ls[i], a );
+ }
+ }
+ mergeInto( &ls, b.ls );
}
if ( b.minl == 0 ) {
- mergeInto( &ranchors, b.ranchors );
- if ( b.skipanchors != 0 ) {
- for ( int i = 0; i < (int) rs.size(); i++ ) {
- int a = eng->anchorConcatenation( at(ranchors, rs[i]),
- b.skipanchors );
- ranchors.insert( rs[i], a );
- }
- }
- mergeInto( &rs, b.rs );
+ mergeInto( &ranchors, b.ranchors );
+ if ( b.skipanchors != 0 ) {
+ for ( int i = 0; i < (int) rs.size(); i++ ) {
+ int a = eng->anchorConcatenation( at(ranchors, rs[i]),
+ b.skipanchors );
+ ranchors.insert( rs[i], a );
+ }
+ }
+ mergeInto( &rs, b.rs );
} else {
- ranchors = b.ranchors;
- rs = b.rs;
+ ranchors = b.ranchors;
+ rs = b.rs;
}
#ifndef QT_NO_REGEXP_OPTIM
if ( maxl != InftyLen ) {
- if ( rightStr.length() + b.leftStr.length() >
- QMAX(str.length(), b.str.length()) ) {
- earlyStart = minl - rightStr.length();
- lateStart = maxl - rightStr.length();
- str = rightStr + b.leftStr;
- } else if ( b.str.length() > str.length() ) {
- earlyStart = minl + b.earlyStart;
- lateStart = maxl + b.lateStart;
- str = b.str;
- }
+ if ( rightStr.length() + b.leftStr.length() >
+ QMAX(str.length(), b.str.length()) ) {
+ earlyStart = minl - rightStr.length();
+ lateStart = maxl - rightStr.length();
+ str = rightStr + b.leftStr;
+ } else if ( b.str.length() > str.length() ) {
+ earlyStart = minl + b.earlyStart;
+ lateStart = maxl + b.lateStart;
+ str = b.str;
+ }
}
if ( (int) leftStr.length() == maxl )
- leftStr += b.leftStr;
+ leftStr += b.leftStr;
if ( (int) b.rightStr.length() == b.maxl )
- rightStr += b.rightStr;
+ rightStr += b.rightStr;
else
- rightStr = b.rightStr;
+ rightStr = b.rightStr;
if ( maxl == InftyLen || b.maxl == InftyLen )
- maxl = InftyLen;
+ maxl = InftyLen;
else
- maxl += b.maxl;
+ maxl += b.maxl;
occ1.detach();
for ( int i = 0; i < NumBadChars; i++ ) {
- if ( b.occ1[i] != NoOccurrence && minl + b.occ1[i] < occ1[i] )
- occ1[i] = minl + b.occ1[i];
+ if ( b.occ1[i] != NoOccurrence && minl + b.occ1[i] < occ1[i] )
+ occ1[i] = minl + b.occ1[i];
}
#endif
minl += b.minl;
if ( minl == 0 )
- skipanchors = eng->anchorConcatenation( skipanchors, b.skipanchors );
+ skipanchors = eng->anchorConcatenation( skipanchors, b.skipanchors );
else
- skipanchors = 0;
+ skipanchors = 0;
}
void QRegExpEngine::Box::orx( const Box& b )
{
mergeInto( &ls, b.ls );
mergeInto( &lanchors, b.lanchors );
mergeInto( &rs, b.rs );
mergeInto( &ranchors, b.ranchors );
skipanchors = eng->anchorAlternation( skipanchors, b.skipanchors );
#ifndef QT_NO_REGEXP_OPTIM
occ1.detach();
for ( int i = 0; i < NumBadChars; i++ ) {
- if ( occ1[i] > b.occ1[i] )
- occ1[i] = b.occ1[i];
+ if ( occ1[i] > b.occ1[i] )
+ occ1[i] = b.occ1[i];
}
earlyStart = 0;
lateStart = 0;
str = QString::null;
leftStr = QString::null;
rightStr = QString::null;
if ( b.maxl > maxl )
- maxl = b.maxl;
+ maxl = b.maxl;
#endif
if ( b.minl < minl )
- minl = b.minl;
+ minl = b.minl;
}
void QRegExpEngine::Box::plus( int atom )
{
#ifndef QT_NO_REGEXP_CAPTURE
eng->addPlusTransitions( rs, ls, atom );
#else
Q_UNUSED( atom );
eng->addCatTransitions( rs, ls );
#endif
addAnchorsToEngine( *this );
#ifndef QT_NO_REGEXP_OPTIM
maxl = InftyLen;
#endif
}
void QRegExpEngine::Box::opt()
{
#ifndef QT_NO_REGEXP_OPTIM
earlyStart = 0;
lateStart = 0;
str = QString::null;
leftStr = QString::null;
rightStr = QString::null;
#endif
skipanchors = 0;
minl = 0;
}
void QRegExpEngine::Box::catAnchor( int a )
{
if ( a != 0 ) {
- for ( int i = 0; i < (int) rs.size(); i++ ) {
- a = eng->anchorConcatenation( at(ranchors, rs[i]), a );
- ranchors.insert( rs[i], a );
- }
- if ( minl == 0 )
- skipanchors = eng->anchorConcatenation( skipanchors, a );
+ for ( int i = 0; i < (int) rs.size(); i++ ) {
+ a = eng->anchorConcatenation( at(ranchors, rs[i]), a );
+ ranchors.insert( rs[i], a );
+ }
+ if ( minl == 0 )
+ skipanchors = eng->anchorConcatenation( skipanchors, a );
}
}
#ifndef QT_NO_REGEXP_OPTIM
void QRegExpEngine::Box::setupHeuristics()
{
eng->setupGoodStringHeuristic( earlyStart, lateStart, str );
/*
A regular expression such as 112|1 has occ1['2'] = 2 and minl = 1 at this
point. An entry of occ1 has to be at most minl or infinity for the rest
of the algorithm to go well.
We waited until here before normalizing these cases (instead of doing it
in Box::orx()) because sometimes things improve by themselves; consider
(112|1)34.
*/
for ( int i = 0; i < NumBadChars; i++ ) {
- if ( occ1[i] != NoOccurrence && occ1[i] >= minl )
- occ1[i] = minl;
+ if ( occ1[i] != NoOccurrence && occ1[i] >= minl )
+ occ1[i] = minl;
}
eng->setupBadCharHeuristic( minl, occ1 );
eng->heuristicallyChooseHeuristic();
}
#endif
#if defined(QT_DEBUG)
void QRegExpEngine::Box::dump() const
{
int i;
- qDebug( "Box of at least %d character%s", minl, minl == 1 ? "" : "s" );
- qDebug( " Left states:" );
+ odebug << "Box of at least " << minl << " character" << (minl == 1 ? "" : "s") << oendl;
+ odebug << " Left states:" << oendl;
for ( i = 0; i < (int) ls.size(); i++ ) {
- if ( at(lanchors, ls[i]) == 0 )
- qDebug( " %d", ls[i] );
- else
- qDebug( " %d [anchors 0x%.8x]", ls[i], lanchors[ls[i]] );
+ if ( at(lanchors, ls[i]) == 0 )
+ odebug << " " << ls[i] << oendl;
+ else
+ odebug << " " << ls[i] << QString().sprintf(" [anchors 0x%.8x]", lanchors[ls[i]]) << oendl;
}
- qDebug( " Right states:" );
+ odebug << " Right states:" << oendl;
for ( i = 0; i < (int) rs.size(); i++ ) {
- if ( at(ranchors, ls[i]) == 0 )
- qDebug( " %d", rs[i] );
- else
- qDebug( " %d [anchors 0x%.8x]", rs[i], ranchors[rs[i]] );
+ if ( at(ranchors, ls[i]) == 0 )
+ odebug << " " << rs[i] << oendl;
+ else
+ odebug << " " << rs[i] << QString().sprintf(" [anchors 0x%.8x]", ranchors[rs[i]]) << oendl;
}
- qDebug( " Skip anchors: 0x%.8x", skipanchors );
+ odebug << QString().sprintf(" Skip anchors: 0x%.8x", skipanchors) << oendl;
}
#endif
void QRegExpEngine::Box::addAnchorsToEngine( const Box& to ) const
{
for ( int i = 0; i < (int) to.ls.size(); i++ ) {
- for ( int j = 0; j < (int) rs.size(); j++ ) {
- int a = eng->anchorConcatenation( at(ranchors, rs[j]),
- at(to.lanchors, to.ls[i]) );
- eng->addAnchors( rs[j], to.ls[i], a );
- }
+ for ( int j = 0; j < (int) rs.size(); j++ ) {
+ int a = eng->anchorConcatenation( at(ranchors, rs[j]),
+ at(to.lanchors, to.ls[i]) );
+ eng->addAnchors( rs[j], to.ls[i], a );
+ }
}
}
int QRegExpEngine::getChar()
{
return ( yyPos == yyLen ) ? EOS : yyIn[yyPos++].unicode();
}
int QRegExpEngine::getEscape()
{
#ifndef QT_NO_REGEXP_ESCAPE
const char tab[] = "afnrtv"; // no b, as \b means word boundary
const char backTab[] = "\a\f\n\r\t\v";
ushort low;
int i;
#endif
ushort val;
int prevCh = yyCh;
if ( prevCh == EOS ) {
- yyError = TRUE;
- return Tok_Char | '\\';
+ yyError = TRUE;
+ return Tok_Char | '\\';
}
yyCh = getChar();
#ifndef QT_NO_REGEXP_ESCAPE
if ( (prevCh & ~0xff) == 0 ) {
- const char *p = strchr( tab, prevCh );
- if ( p != 0 )
- return Tok_Char | backTab[p - tab];
+ const char *p = strchr( tab, prevCh );
+ if ( p != 0 )
+ return Tok_Char | backTab[p - tab];
}
#endif
switch ( prevCh ) {
#ifndef QT_NO_REGEXP_ESCAPE
case '0':
- val = 0;
- for ( i = 0; i < 3; i++ ) {
- if ( yyCh >= '0' && yyCh <= '7' )
- val = ( val << 3 ) | ( yyCh - '0' );
- else
- break;
- yyCh = getChar();
- }
- if ( (val & ~0377) != 0 )
- yyError = TRUE;
- return Tok_Char | val;
+ val = 0;
+ for ( i = 0; i < 3; i++ ) {
+ if ( yyCh >= '0' && yyCh <= '7' )
+ val = ( val << 3 ) | ( yyCh - '0' );
+ else
+ break;
+ yyCh = getChar();
+ }
+ if ( (val & ~0377) != 0 )
+ yyError = TRUE;
+ return Tok_Char | val;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'B':
- return Tok_NonWord;
+ return Tok_NonWord;
#endif
#ifndef QT_NO_REGEXP_CCLASS
case 'D':
- // see QChar::isDigit()
- yyCharClass->addCategories( 0x7fffffef );
- return Tok_CharClass;
+ // see QChar::isDigit()
+ yyCharClass->addCategories( 0x7fffffef );
+ return Tok_CharClass;
case 'S':
- // see QChar::isSpace()
- yyCharClass->addCategories( 0x7ffff87f );
- yyCharClass->addRange( 0x0000, 0x0008 );
- yyCharClass->addRange( 0x000e, 0x001f );
- yyCharClass->addRange( 0x007f, 0x009f );
- return Tok_CharClass;
+ // see QChar::isSpace()
+ yyCharClass->addCategories( 0x7ffff87f );
+ yyCharClass->addRange( 0x0000, 0x0008 );
+ yyCharClass->addRange( 0x000e, 0x001f );
+ yyCharClass->addRange( 0x007f, 0x009f );
+ return Tok_CharClass;
case 'W':
- // see QChar::isLetterOrNumber()
- yyCharClass->addCategories( 0x7ff07f8f );
- return Tok_CharClass;
+ // see QChar::isLetterOrNumber()
+ yyCharClass->addCategories( 0x7ff07f8f );
+ return Tok_CharClass;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'b':
- return Tok_Word;
+ return Tok_Word;
#endif
#ifndef QT_NO_REGEXP_CCLASS
case 'd':
- // see QChar::isDigit()
- yyCharClass->addCategories( 0x00000010 );
- return Tok_CharClass;
+ // see QChar::isDigit()
+ yyCharClass->addCategories( 0x00000010 );
+ return Tok_CharClass;
case 's':
- // see QChar::isSpace()
- yyCharClass->addCategories( 0x00000380 );
- yyCharClass->addRange( 0x0009, 0x000d );
- return Tok_CharClass;
+ // see QChar::isSpace()
+ yyCharClass->addCategories( 0x00000380 );
+ yyCharClass->addRange( 0x0009, 0x000d );
+ return Tok_CharClass;
case 'w':
- // see QChar::isLetterOrNumber()
- yyCharClass->addCategories( 0x000f8070 );
- return Tok_CharClass;
+ // see QChar::isLetterOrNumber()
+ yyCharClass->addCategories( 0x000f8070 );
+ return Tok_CharClass;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'x':
- val = 0;
- for ( i = 0; i < 4; i++ ) {
- low = QChar( yyCh ).lower();
- if ( low >= '0' && low <= '9' )
- val = ( val << 4 ) | ( low - '0' );
- else if ( low >= 'a' && low <= 'f' )
- val = ( val << 4 ) | ( low - 'a' + 10 );
- else
- break;
- yyCh = getChar();
- }
- return Tok_Char | val;
+ val = 0;
+ for ( i = 0; i < 4; i++ ) {
+ low = QChar( yyCh ).lower();
+ if ( low >= '0' && low <= '9' )
+ val = ( val << 4 ) | ( low - '0' );
+ else if ( low >= 'a' && low <= 'f' )
+ val = ( val << 4 ) | ( low - 'a' + 10 );
+ else
+ break;
+ yyCh = getChar();
+ }
+ return Tok_Char | val;
#endif
default:
- if ( prevCh >= '1' && prevCh <= '9' ) {
+ if ( prevCh >= '1' && prevCh <= '9' ) {
#ifndef QT_NO_REGEXP_BACKREF
- val = prevCh - '0';
- while ( yyCh >= '0' && yyCh <= '9' ) {
- val = ( val *= 10 ) | ( yyCh - '0' );
- yyCh = getChar();
- }
- return Tok_BackRef | val;
+ val = prevCh - '0';
+ while ( yyCh >= '0' && yyCh <= '9' ) {
+ val = ( val *= 10 ) | ( yyCh - '0' );
+ yyCh = getChar();
+ }
+ return Tok_BackRef | val;
#else
- yyError = TRUE;
+ yyError = TRUE;
#endif
- }
- return Tok_Char | prevCh;
+ }
+ return Tok_Char | prevCh;
}
}
#ifndef QT_NO_REGEXP_INTERVAL
int QRegExpEngine::getRep( int def )
{
if ( yyCh >= '0' && yyCh <= '9' ) {
- int rep = 0;
- do {
- rep = 10 * rep + yyCh - '0';
- if ( rep >= InftyRep ) {
- yyError = TRUE;
- rep = def;
- }
- yyCh = getChar();
- } while ( yyCh >= '0' && yyCh <= '9' );
- return rep;
+ int rep = 0;
+ do {
+ rep = 10 * rep + yyCh - '0';
+ if ( rep >= InftyRep ) {
+ yyError = TRUE;
+ rep = def;
+ }
+ yyCh = getChar();
+ } while ( yyCh >= '0' && yyCh <= '9' );
+ return rep;
} else {
- return def;
+ return def;
}
}
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
void QRegExpEngine::skipChars( int n )
{
if ( n > 0 ) {
- yyPos += n - 1;
- yyCh = getChar();
+ yyPos += n - 1;
+ yyCh = getChar();
}
}
#endif
void QRegExpEngine::startTokenizer( const QChar *rx, int len )
{
yyIn = rx;
yyPos0 = 0;
yyPos = 0;
yyLen = len;
yyCh = getChar();
yyCharClass = new CharClass;
yyMinRep = 0;
yyMaxRep = 0;
yyError = FALSE;
}
int QRegExpEngine::getToken()
{
#ifndef QT_NO_REGEXP_CCLASS
ushort pendingCh = 0;
bool charPending;
bool rangePending;
int tok;
#endif
int prevCh = yyCh;
yyPos0 = yyPos - 1;
#ifndef QT_NO_REGEXP_CCLASS
yyCharClass->clear();
#endif
yyMinRep = 0;
yyMaxRep = 0;
yyCh = getChar();
switch ( prevCh ) {
case EOS:
- yyPos0 = yyPos;
- return Tok_Eos;
+ yyPos0 = yyPos;
+ return Tok_Eos;
case '$':
- return Tok_Dollar;
+ return Tok_Dollar;
case '(':
- if ( yyCh == '?' ) {
- prevCh = getChar();
- yyCh = getChar();
- switch ( prevCh ) {
+ if ( yyCh == '?' ) {
+ prevCh = getChar();
+ yyCh = getChar();
+ switch ( prevCh ) {
#ifndef QT_NO_REGEXP_LOOKAHEAD
- case '!':
- return Tok_NegLookahead;
- case '=':
- return Tok_PosLookahead;
-#endif
- case ':':
- return Tok_MagicLeftParen;
- default:
- yyError = TRUE;
- return Tok_MagicLeftParen;
- }
- } else {
- return Tok_LeftParen;
- }
+ case '!':
+ return Tok_NegLookahead;
+ case '=':
+ return Tok_PosLookahead;
+#endif
+ case ':':
+ return Tok_MagicLeftParen;
+ default:
+ yyError = TRUE;
+ return Tok_MagicLeftParen;
+ }
+ } else {
+ return Tok_LeftParen;
+ }
case ')':
- return Tok_RightParen;
+ return Tok_RightParen;
case '*':
- yyMinRep = 0;
- yyMaxRep = InftyRep;
- return Tok_Quantifier;
+ yyMinRep = 0;
+ yyMaxRep = InftyRep;
+ return Tok_Quantifier;
case '+':
- yyMinRep = 1;
- yyMaxRep = InftyRep;
- return Tok_Quantifier;
+ yyMinRep = 1;
+ yyMaxRep = InftyRep;
+ return Tok_Quantifier;
case '.':
#ifndef QT_NO_REGEXP_CCLASS
- yyCharClass->setNegative( TRUE );
+ yyCharClass->setNegative( TRUE );
#endif
- return Tok_CharClass;
+ return Tok_CharClass;
case '?':
- yyMinRep = 0;
- yyMaxRep = 1;
- return Tok_Quantifier;
+ yyMinRep = 0;
+ yyMaxRep = 1;
+ return Tok_Quantifier;
case '[':
#ifndef QT_NO_REGEXP_CCLASS
- if ( yyCh == '^' ) {
- yyCharClass->setNegative( TRUE );
- yyCh = getChar();
- }
- charPending = FALSE;
- rangePending = FALSE;
- do {
- if ( yyCh == '-' && charPending && !rangePending ) {
- rangePending = TRUE;
- yyCh = getChar();
- } else {
- if ( charPending && !rangePending ) {
- yyCharClass->addSingleton( pendingCh );
- charPending = FALSE;
- }
- if ( yyCh == '\\' ) {
- yyCh = getChar();
- tok = getEscape();
- if ( tok == Tok_Word )
- tok = '\b';
- } else {
- tok = Tok_Char | yyCh;
- yyCh = getChar();
- }
- if ( tok == Tok_CharClass ) {
- if ( rangePending ) {
- yyCharClass->addSingleton( '-' );
- yyCharClass->addSingleton( pendingCh );
- charPending = FALSE;
- rangePending = FALSE;
- }
- } else if ( (tok & Tok_Char) != 0 ) {
- if ( rangePending ) {
- yyCharClass->addRange( pendingCh, tok ^ Tok_Char );
- charPending = FALSE;
- rangePending = FALSE;
- } else {
- pendingCh = tok ^ Tok_Char;
- charPending = TRUE;
- }
- } else {
- yyError = TRUE;
- }
- }
- } while ( yyCh != ']' && yyCh != EOS );
- if ( rangePending )
- yyCharClass->addSingleton( '-' );
- if ( charPending )
- yyCharClass->addSingleton( pendingCh );
- if ( yyCh == EOS )
- yyError = TRUE;
- else
- yyCh = getChar();
- return Tok_CharClass;
+ if ( yyCh == '^' ) {
+ yyCharClass->setNegative( TRUE );
+ yyCh = getChar();
+ }
+ charPending = FALSE;
+ rangePending = FALSE;
+ do {
+ if ( yyCh == '-' && charPending && !rangePending ) {
+ rangePending = TRUE;
+ yyCh = getChar();
+ } else {
+ if ( charPending && !rangePending ) {
+ yyCharClass->addSingleton( pendingCh );
+ charPending = FALSE;
+ }
+ if ( yyCh == '\\' ) {
+ yyCh = getChar();
+ tok = getEscape();
+ if ( tok == Tok_Word )
+ tok = '\b';
+ } else {
+ tok = Tok_Char | yyCh;
+ yyCh = getChar();
+ }
+ if ( tok == Tok_CharClass ) {
+ if ( rangePending ) {
+ yyCharClass->addSingleton( '-' );
+ yyCharClass->addSingleton( pendingCh );
+ charPending = FALSE;
+ rangePending = FALSE;
+ }
+ } else if ( (tok & Tok_Char) != 0 ) {
+ if ( rangePending ) {
+ yyCharClass->addRange( pendingCh, tok ^ Tok_Char );
+ charPending = FALSE;
+ rangePending = FALSE;
+ } else {
+ pendingCh = tok ^ Tok_Char;
+ charPending = TRUE;
+ }
+ } else {
+ yyError = TRUE;
+ }
+ }
+ } while ( yyCh != ']' && yyCh != EOS );
+ if ( rangePending )
+ yyCharClass->addSingleton( '-' );
+ if ( charPending )
+ yyCharClass->addSingleton( pendingCh );
+ if ( yyCh == EOS )
+ yyError = TRUE;
+ else
+ yyCh = getChar();
+ return Tok_CharClass;
#else
- yyError = TRUE;
- return Tok_Char | '[';
+ yyError = TRUE;
+ return Tok_Char | '[';
#endif
case '\\':
- return getEscape();
+ return getEscape();
case ']':
- yyError = TRUE;
- return Tok_Char | ']';
+ yyError = TRUE;
+ return Tok_Char | ']';
case '^':
- return Tok_Caret;
+ return Tok_Caret;
#ifndef QT_NO_REGEXP_INTERVAL
case '{':
- yyMinRep = getRep( 0 );
- yyMaxRep = yyMinRep;
- if ( yyCh == ',' ) {
- yyCh = getChar();
- yyMaxRep = getRep( InftyRep );
- }
- if ( yyMaxRep < yyMinRep )
- qSwap( yyMinRep, yyMaxRep );
- if ( yyCh != '}' )
- yyError = TRUE;
- yyCh = getChar();
- return Tok_Quantifier;
+ yyMinRep = getRep( 0 );
+ yyMaxRep = yyMinRep;
+ if ( yyCh == ',' ) {
+ yyCh = getChar();
+ yyMaxRep = getRep( InftyRep );
+ }
+ if ( yyMaxRep < yyMinRep )
+ qSwap( yyMinRep, yyMaxRep );
+ if ( yyCh != '}' )
+ yyError = TRUE;
+ yyCh = getChar();
+ return Tok_Quantifier;
#else
- yyError = TRUE;
- return Tok_Char | '{';
+ yyError = TRUE;
+ return Tok_Char | '{';
#endif
case '|':
- return Tok_Bar;
+ return Tok_Bar;
case '}':
- yyError = TRUE;
- return Tok_Char | '}';
+ yyError = TRUE;
+ return Tok_Char | '}';
default:
- return Tok_Char | prevCh;
+ return Tok_Char | prevCh;
}
}
int QRegExpEngine::parse( const QChar *pattern, int len )
{
valid = TRUE;
startTokenizer( pattern, len );
yyTok = getToken();
#ifndef QT_NO_REGEXP_CAPTURE
yyMayCapture = TRUE;
#else
yyMayCapture = FALSE;
#endif
#ifndef QT_NO_REGEXP_CAPTURE
int atom = startAtom( FALSE );
#endif
CharClass anything;
Box box( this ); // create InitialState
box.set( anything );
Box rightBox( this ); // create FinalState
rightBox.set( anything );
Box middleBox( this );
parseExpression( &middleBox );
#ifndef QT_NO_REGEXP_CAPTURE
finishAtom( atom );
#endif
#ifndef QT_NO_REGEXP_OPTIM
middleBox.setupHeuristics();
#endif
box.cat( middleBox );
box.cat( rightBox );
delete yyCharClass;
yyCharClass = 0;
realncap = ncap;
#ifndef QT_NO_REGEXP_BACKREF
if ( nbrefs > ncap )
- ncap = nbrefs;
+ ncap = nbrefs;
#endif
mmCaptured.resize( 2 + 2 * realncap );
mmCapturedNoMatch.fill( -1, 2 + 2 * realncap );
/*
We use one QArray<int> for all the big data used a lot in matchHere() and
friends.
*/
#ifndef QT_NO_REGEXP_OPTIM
mmSlideTabSize = QMAX( minl + 1, 16 );
#else
mmSlideTabSize = 0;
#endif
mmBigArray.resize( (3 + 4 * ncap) * ns + 4 * ncap + mmSlideTabSize );
mmInNextStack = mmBigArray.data();
memset( mmInNextStack, -1, ns * sizeof(int) );
mmCurStack = mmInNextStack + ns;
mmNextStack = mmInNextStack + 2 * ns;
mmCurCapBegin = mmInNextStack + 3 * ns;
mmNextCapBegin = mmCurCapBegin + ncap * ns;
mmCurCapEnd = mmCurCapBegin + 2 * ncap * ns;
mmNextCapEnd = mmCurCapBegin + 3 * ncap * ns;
mmTempCapBegin = mmCurCapBegin + 4 * ncap * ns;
mmTempCapEnd = mmTempCapBegin + ncap;
mmCapBegin = mmTempCapBegin + 2 * ncap;
mmCapEnd = mmTempCapBegin + 3 * ncap;
mmSlideTab = mmTempCapBegin + 4 * ncap;
if ( yyError )
- return -1;
+ return -1;
#ifndef QT_NO_REGEXP_OPTIM
State *sinit = s[InitialState];
caretAnchored = ( sinit->anchors != 0 );
if ( caretAnchored ) {
- QMap<int, int>& anchors = *sinit->anchors;
- QMap<int, int>::ConstIterator a;
- for ( a = anchors.begin(); a != anchors.end(); ++a ) {
+ QMap<int, int>& anchors = *sinit->anchors;
+ QMap<int, int>::ConstIterator a;
+ for ( a = anchors.begin(); a != anchors.end(); ++a ) {
#ifndef QT_NO_REGEXP_ANCHOR_ALT
- if ( (*a & Anchor_Alternation) != 0 )
- break;
+ if ( (*a & Anchor_Alternation) != 0 )
+ break;
#endif
- if ( (*a & Anchor_Caret) == 0 ) {
- caretAnchored = FALSE;
- break;
- }
- }
+ if ( (*a & Anchor_Caret) == 0 ) {
+ caretAnchored = FALSE;
+ break;
+ }
+ }
}
#endif
return yyPos0;
}
void QRegExpEngine::parseAtom( Box *box )
{
#ifndef QT_NO_REGEXP_LOOKAHEAD
QRegExpEngine *eng = 0;
bool neg;
int len;
#endif
switch ( yyTok ) {
case Tok_Dollar:
- box->catAnchor( Anchor_Dollar );
- break;
+ box->catAnchor( Anchor_Dollar );
+ break;
case Tok_Caret:
- box->catAnchor( Anchor_Caret );
- break;
+ box->catAnchor( Anchor_Caret );
+ break;
#ifndef QT_NO_REGEXP_LOOKAHEAD
case Tok_PosLookahead:
case Tok_NegLookahead:
- neg = ( yyTok == Tok_NegLookahead );
- eng = new QRegExpEngine( cs );
- len = eng->parse( yyIn + yyPos - 1, yyLen - yyPos + 1 );
- if ( len >= 0 )
- skipChars( len );
- else
- yyError = TRUE;
- box->catAnchor( addLookahead(eng, neg) );
- yyTok = getToken();
- if ( yyTok != Tok_RightParen )
- yyError = TRUE;
- break;
+ neg = ( yyTok == Tok_NegLookahead );
+ eng = new QRegExpEngine( cs );
+ len = eng->parse( yyIn + yyPos - 1, yyLen - yyPos + 1 );
+ if ( len >= 0 )
+ skipChars( len );
+ else
+ yyError = TRUE;
+ box->catAnchor( addLookahead(eng, neg) );
+ yyTok = getToken();
+ if ( yyTok != Tok_RightParen )
+ yyError = TRUE;
+ break;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case Tok_Word:
- box->catAnchor( Anchor_Word );
- break;
+ box->catAnchor( Anchor_Word );
+ break;
case Tok_NonWord:
- box->catAnchor( Anchor_NonWord );
- break;
+ box->catAnchor( Anchor_NonWord );
+ break;
#endif
case Tok_LeftParen:
case Tok_MagicLeftParen:
- yyTok = getToken();
- parseExpression( box );
- if ( yyTok != Tok_RightParen )
- yyError = TRUE;
- break;
+ yyTok = getToken();
+ parseExpression( box );
+ if ( yyTok != Tok_RightParen )
+ yyError = TRUE;
+ break;
case Tok_CharClass:
- box->set( *yyCharClass );
- break;
+ box->set( *yyCharClass );
+ break;
default:
- if ( (yyTok & Tok_Char) != 0 )
- box->set( QChar(yyTok ^ Tok_Char) );
+ if ( (yyTok & Tok_Char) != 0 )
+ box->set( QChar(yyTok ^ Tok_Char) );
#ifndef QT_NO_REGEXP_BACKREF
- else if ( (yyTok & Tok_BackRef) != 0 )
- box->set( yyTok ^ Tok_BackRef );
+ else if ( (yyTok & Tok_BackRef) != 0 )
+ box->set( yyTok ^ Tok_BackRef );
#endif
- else
- yyError = TRUE;
+ else
+ yyError = TRUE;
}
yyTok = getToken();
}
void QRegExpEngine::parseFactor( Box *box )
{
#ifndef QT_NO_REGEXP_CAPTURE
int atom = startAtom( yyMayCapture && yyTok == Tok_LeftParen );
#else
static const int atom = 0;
#endif
#ifndef QT_NO_REGEXP_INTERVAL
#define YYREDO() \
- yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \
- *yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok
+ yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \
+ *yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok
const QChar *in = yyIn;
int pos0 = yyPos0;
int pos = yyPos;
int len = yyLen;
int ch = yyCh;
CharClass charClass;
if ( yyTok == Tok_CharClass )
- charClass = *yyCharClass;
+ charClass = *yyCharClass;
int tok = yyTok;
bool mayCapture = yyMayCapture;
#endif
parseAtom( box );
#ifndef QT_NO_REGEXP_CAPTURE
finishAtom( atom );
#endif
if ( yyTok == Tok_Quantifier ) {
- if ( yyMaxRep == InftyRep ) {
- box->plus( atom );
+ if ( yyMaxRep == InftyRep ) {
+ box->plus( atom );
#ifndef QT_NO_REGEXP_INTERVAL
- } else if ( yyMaxRep == 0 ) {
- box->clear();
+ } else if ( yyMaxRep == 0 ) {
+ box->clear();
#endif
- }
- if ( yyMinRep == 0 )
- box->opt();
+ }
+ if ( yyMinRep == 0 )
+ box->opt();
#ifndef QT_NO_REGEXP_INTERVAL
- yyMayCapture = FALSE;
- int alpha = ( yyMinRep == 0 ) ? 0 : yyMinRep - 1;
- int beta = ( yyMaxRep == InftyRep ) ? 0 : yyMaxRep - ( alpha + 1 );
-
- Box rightBox( this );
- int i;
-
- for ( i = 0; i < beta; i++ ) {
- YYREDO();
- Box leftBox( this );
- parseAtom( &leftBox );
- leftBox.cat( rightBox );
- leftBox.opt();
- rightBox = leftBox;
- }
- for ( i = 0; i < alpha; i++ ) {
- YYREDO();
- Box leftBox( this );
- parseAtom( &leftBox );
- leftBox.cat( rightBox );
- rightBox = leftBox;
- }
- rightBox.cat( *box );
- *box = rightBox;
-#endif
- yyTok = getToken();
+ yyMayCapture = FALSE;
+ int alpha = ( yyMinRep == 0 ) ? 0 : yyMinRep - 1;
+ int beta = ( yyMaxRep == InftyRep ) ? 0 : yyMaxRep - ( alpha + 1 );
+
+ Box rightBox( this );
+ int i;
+
+ for ( i = 0; i < beta; i++ ) {
+ YYREDO();
+ Box leftBox( this );
+ parseAtom( &leftBox );
+ leftBox.cat( rightBox );
+ leftBox.opt();
+ rightBox = leftBox;
+ }
+ for ( i = 0; i < alpha; i++ ) {
+ YYREDO();
+ Box leftBox( this );
+ parseAtom( &leftBox );
+ leftBox.cat( rightBox );
+ rightBox = leftBox;
+ }
+ rightBox.cat( *box );
+ *box = rightBox;
+#endif
+ yyTok = getToken();
#ifndef QT_NO_REGEXP_INTERVAL
- yyMayCapture = mayCapture;
+ yyMayCapture = mayCapture;
#endif
}
#undef YYREDO
}
void QRegExpEngine::parseTerm( Box *box )
{
#ifndef QT_NO_REGEXP_OPTIM
if ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar )
- parseFactor( box );
+ parseFactor( box );
#endif
while ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar ) {
- Box rightBox( this );
- parseFactor( &rightBox );
- box->cat( rightBox );
+ Box rightBox( this );
+ parseFactor( &rightBox );
+ box->cat( rightBox );
}
}
void QRegExpEngine::parseExpression( Box *box )
{
parseTerm( box );
while ( yyTok == Tok_Bar ) {
- Box rightBox( this );
- yyTok = getToken();
- parseTerm( &rightBox );
- box->orx( rightBox );
+ Box rightBox( this );
+ yyTok = getToken();
+ parseTerm( &rightBox );
+ box->orx( rightBox );
}
}
/*
The class QRegExpPrivate contains the private data of a regular expression
other than the automaton. It makes it possible for many QRegExp objects to
use the same QRegExpEngine object with different QRegExpPrivate objects.
*/
struct QRegExpPrivate
{
QString pattern; // regular-expression or wildcard pattern
QString rxpattern; // regular-expression pattern
#ifndef QT_NO_REGEXP_WILDCARD
bool wc; // wildcard mode?
#endif
bool min; // minimal matching? (instead of maximal)
#ifndef QT_NO_REGEXP_CAPTURE
QString t; // last string passed to QRegExp::search() or searchRev()
QStringList capturedCache; // what QRegExp::capturedTexts() returned last
#endif
QArray<int> captured; // what QRegExpEngine::search() returned last
QRegExpPrivate() { captured.fill( -1, 2 ); }
};
#ifndef QT_NO_REGEXP_OPTIM
static QCache<QRegExpEngine> *engineCache = 0;
#endif
static QRegExpEngine *newEngine( const QString& pattern, bool caseSensitive )
{
#ifndef QT_NO_REGEXP_OPTIM
if ( engineCache != 0 ) {
- QRegExpEngine *eng = engineCache->take( pattern );
- if ( eng == 0 || eng->caseSensitive() != caseSensitive ) {
- delete eng;
- } else {
- eng->ref();
- return eng;
- }
+ QRegExpEngine *eng = engineCache->take( pattern );
+ if ( eng == 0 || eng->caseSensitive() != caseSensitive ) {
+ delete eng;
+ } else {
+ eng->ref();
+ return eng;
+ }
}
#endif
return new QRegExpEngine( pattern, caseSensitive );
}
static void derefEngine( QRegExpEngine *eng, const QString& pattern )
{
if ( eng != 0 && eng->deref() ) {
#ifndef QT_NO_REGEXP_OPTIM
- if ( engineCache == 0 ) {
- engineCache = new QCache<QRegExpEngine>;
- engineCache->setAutoDelete( TRUE );
- }
- if ( !pattern.isNull() &&
- engineCache->insert(pattern, eng, 4 + pattern.length() / 4) )
- return;
+ if ( engineCache == 0 ) {
+ engineCache = new QCache<QRegExpEngine>;
+ engineCache->setAutoDelete( TRUE );
+ }
+ if ( !pattern.isNull() &&
+ engineCache->insert(pattern, eng, 4 + pattern.length() / 4) )
+ return;
#else
- Q_UNUSED( pattern );
+ Q_UNUSED( pattern );
#endif
- delete eng;
+ delete eng;
}
}
/*!
Constructs an empty regexp.
\sa isValid()
*/
QRegExp3::QRegExp3()
{
eng = new QRegExpEngine( TRUE );
priv = new QRegExpPrivate;
priv->pattern = QString::null;
#ifndef QT_NO_REGEXP_WILDCARD
priv->wc = FALSE;
#endif
priv->min = FALSE;
compile( TRUE );
}
/*!
Constructs a regular expression object for the given \a pattern
string. The pattern must be given using wildcard notation if \a
wildcard is TRUE (default is FALSE). The pattern is case sensitive,
unless \a caseSensitive is FALSE. Matching is greedy (maximal), but
can be changed by calling setMinimal().
\sa setPattern() setCaseSensitive() setWildcard() setMinimal()
*/
QRegExp3::QRegExp3( const QString& pattern, bool caseSensitive, bool wildcard )
{
eng = 0;
priv = new QRegExpPrivate;
priv->pattern = pattern;
#ifndef QT_NO_REGEXP_WILDCARD
priv->wc = wildcard;
#endif
priv->min = FALSE;
compile( caseSensitive );
}
/*!
Constructs a regular expression as a copy of \a rx.
\sa operator=()
*/
QRegExp3::QRegExp3( const QRegExp3& rx )
{
@@ -3156,612 +3162,612 @@ QRegExp3::QRegExp3( const QRegExp3& rx )
priv = new QRegExpPrivate;
operator=( rx );
}
/*!
Destroys the regular expression and cleans up its internal data.
*/
QRegExp3::~QRegExp3()
{
derefEngine( eng, priv->rxpattern );
delete priv;
}
/*!
Copies the regular expression \a rx and returns a reference to the copy.
The case sensitivity, wildcard and minimal matching options are copied as
well.
*/
QRegExp3& QRegExp3::operator=( const QRegExp3& rx )
{
rx.eng->ref();
derefEngine( eng, priv->rxpattern );
eng = rx.eng;
priv->pattern = rx.priv->pattern;
priv->rxpattern = rx.priv->rxpattern;
#ifndef QT_NO_REGEXP_WILDCARD
priv->wc = rx.priv->wc;
#endif
priv->min = rx.priv->min;
#ifndef QT_NO_REGEXP_CAPTURE
priv->t = rx.priv->t;
priv->capturedCache = rx.priv->capturedCache;
#endif
priv->captured = rx.priv->captured;
return *this;
}
/*!
Returns TRUE if this regular expression is equal to \a rx, otherwise
returns FALSE.
Two QRegExp3 objects are equal if they have the same pattern strings
and the same settings for case sensitivity, wildcard and minimal
matching.
*/
bool QRegExp3::operator==( const QRegExp3& rx ) const
{
return priv->pattern == rx.priv->pattern &&
- eng->caseSensitive() == rx.eng->caseSensitive() &&
+ eng->caseSensitive() == rx.eng->caseSensitive() &&
#ifndef QT_NO_REGEXP_WILDCARD
- priv->wc == rx.priv->wc &&
+ priv->wc == rx.priv->wc &&
#endif
- priv->min == rx.priv->min;
+ priv->min == rx.priv->min;
}
/*! \fn bool QRegExp3::operator!=( const QRegExp& rx ) const
Returns TRUE if this regular expression is not equal to \a rx, otherwise
FALSE.
\sa operator==()
*/
/*!
Returns TRUE if the pattern string is empty, otherwise FALSE.
If you call match() with an empty pattern on an empty string it will
return TRUE otherwise it returns FALSE since match() operates over the
whole string. If you call search() with an empty pattern on \e any
string it will return the start position (0 by default) since it will
match at the start position, because the empty pattern matches the
'emptiness' at the start of the string, and the length of the match
returned by matchedLength() will be 0.
See QString::isEmpty().
*/
bool QRegExp3::isEmpty() const
{
return priv->pattern.isEmpty();
}
/*!
Returns TRUE if the regular expression is valid, or FALSE if it's invalid. An
invalid regular expression never matches.
The pattern <b>[a-z</b> is an example of an invalid pattern, since it lacks
a closing square bracket.
Note that the validity of a regexp may also depend on the setting of
the wildcard flag, for example <b>*.html</b> is a valid wildcard
regexp but an invalid full regexp.
*/
bool QRegExp3::isValid() const
{
return eng->isValid();
}
/*!
Returns the pattern string of the regular expression. The pattern has either
regular expression syntax or wildcard syntax, depending on wildcard().
\sa setPattern()
*/
QString QRegExp3::pattern() const
{
return priv->pattern;
}
/*!
Sets the pattern string to \a pattern and returns a reference to this regular
expression. The case sensitivity, wildcard and minimal matching options are
not changed.
\sa pattern()
*/
void QRegExp3::setPattern( const QString& pattern )
{
if ( priv->pattern != pattern ) {
- priv->pattern = pattern;
- compile( caseSensitive() );
+ priv->pattern = pattern;
+ compile( caseSensitive() );
}
}
/*!
Returns TRUE if case sensitivity is enabled, otherwise FALSE. The default is
TRUE.
\sa setCaseSensitive()
*/
bool QRegExp3::caseSensitive() const
{
return eng->caseSensitive();
}
/*!
Sets case sensitive matching to \a sensitive.
If \a sensitive is TRUE, <b>\\</b><b>.txt$</b> matches
<tt>readme.txt</tt> but not <tt>README.TXT</tt>.
\sa caseSensitive()
*/
void QRegExp3::setCaseSensitive( bool sensitive )
{
if ( sensitive != eng->caseSensitive() )
- compile( sensitive );
+ compile( sensitive );
}
#ifndef QT_NO_REGEXP_WILDCARD
/*!
Returns TRUE if wildcard mode is enabled, otherwise FALSE. The default is
FALSE.
\sa setWildcard()
*/
bool QRegExp3::wildcard() const
{
return priv->wc;
}
/*! Sets the wildcard mode for the regular expression. The default is FALSE.
Setting \a wildcard to TRUE enables simple shell-like wildcard
matching.
(See <a href="#wildcard-matching">wildcard matching (globbing)</a>.)
For example, <b>r*.txt</b> matches the string <tt>readme.txt</tt> in wildcard
mode, but does not match <tt>readme</tt>.
\sa wildcard()
*/
void QRegExp3::setWildcard( bool wildcard )
{
if ( wildcard != priv->wc ) {
- priv->wc = wildcard;
- compile( caseSensitive() );
+ priv->wc = wildcard;
+ compile( caseSensitive() );
}
}
#endif
/*! Returns TRUE if minimal (non-greedy) matching is enabled, otherwise
returns FALSE.
\sa setMinimal()
*/
bool QRegExp3::minimal() const
{
return priv->min;
}
/*!
Enables or disables minimal matching. If \a minimal is FALSE, matching is
greedy (maximal) which is the default.
For example, suppose we have the input string "We must be \<b>bold\</b>,
very \<b>bold\</b>!" and the pattern <b>\<b>.*\</b></b>. With
the default greedy (maximal) matching, the match is
"We must be <u>\<b>bold\</b>, very \<b>bold\</b></u>!". But with
minimal (non-greedy) matching the first match is:
"We must be <u>\<b>bold\</b></u>, very \<b>bold\</b>!" and the
second match is
"We must be \<b>bold\</b>, very <u>\<b>bold\</b></u>!".
In practice we might use the pattern <b>\<b>[^\<]+\</b></b>,
although this will still fail for nested tags.
\sa minimal()
*/
void QRegExp3::setMinimal( bool minimal )
{
priv->min = minimal;
}
/*!
Returns TRUE if \a str is matched exactly by this regular expression
otherwise it returns FALSE. You can determine how much of the string was
matched by calling matchedLength().
For a given regexp string, R, <tt>match("R")</tt> is the equivalent
of <tt>search("^R$")</tt> since match() effectively encloses the
regexp in the start of string and end of string anchors.
For example, if the regular expression is <b>blue</b>, then match()
returns TRUE only for input <tt>blue</tt>. For inputs
<tt>bluebell</tt>, <tt>blutak</tt> and <tt>lightblue</tt>, match()
returns FALSE and matchedLength() will return 4, 3 and 0 respectively.
\sa search() searchRev() QRegExpValidator
*/
bool QRegExp3::exactMatch( const QString& str )
{
#ifndef QT_NO_REGEXP_CAPTURE
priv->t = str;
priv->capturedCache.clear();
#endif
priv->captured = eng->match( str, 0, priv->min, TRUE );
if ( priv->captured[1] == (int) str.length() ) {
- return TRUE;
+ return TRUE;
} else {
- priv->captured.detach();
- priv->captured[0] = 0;
- priv->captured[1] = eng->matchedLength();
- return FALSE;
+ priv->captured.detach();
+ priv->captured[0] = 0;
+ priv->captured[1] = eng->matchedLength();
+ return FALSE;
}
}
/*! \overload
This version does not set matchedLength(), capturedTexts() and friends.
*/
bool QRegExp3::exactMatch( const QString& str ) const
{
return eng->match(str, 0, priv->min, TRUE)[0] == 0 &&
- eng->matchedLength() == (int) str.length();
+ eng->matchedLength() == (int) str.length();
}
/*! \obsolete
Attempts to match in \a str, starting from position \a index. Returns the
position of the match, or -1 if there was no match.
The length of the match is stored in \a *len, unless \a len is a null pointer.
If \a indexIsStart is TRUE (the default), the position \a index in the string
will match the start of string anchor, <b>^</b>, in the regexp, if present.
Otherwise, position 0 in \a str will match.
Use search() and matchedLength() instead of this function.
If you really need the \a indexIsStart functionality, try this:
\code
QRegExp3 rx( "some pattern" );
int pos = rx.search( str.mid( index ) );
if ( pos != -1 )
- pos += index;
+ pos += index;
int len = rx.matchedLength();
\endcode
*/
-#ifndef QT_NO_COMPAT
+#ifndef QT_NO_COMPAT
int QRegExp3::match( const QString& str, int index, int *len,
- bool indexIsStart )
+ bool indexIsStart )
{
int pos;
if ( indexIsStart ) {
- pos = search( str.mid(index) );
- if ( pos >= 0 ) {
- pos += index;
- if ( len != 0 )
- *len = matchedLength();
- } else {
- if ( len != 0 )
- *len = 0;
- }
+ pos = search( str.mid(index) );
+ if ( pos >= 0 ) {
+ pos += index;
+ if ( len != 0 )
+ *len = matchedLength();
+ } else {
+ if ( len != 0 )
+ *len = 0;
+ }
} else {
- pos = search( str, index );
- if ( len != 0 )
- *len = matchedLength();
+ pos = search( str, index );
+ if ( len != 0 )
+ *len = matchedLength();
}
return pos;
}
#endif
/*!
Attempts to find a match in \a str from position \a start (0 by default). If
\a start is -1, the search starts at the last character; if -2, at the next to
last character; etc.
Returns the position of the first match, or -1 if there was no match.
You might prefer to use QString::find(), QString::contains() or even
QStringList::grep(). To replace matches use QString::replace().
Example:
\code
QString str = "offsets: 1.23 .50 71.00 6.00";
QRegExp3 rx( "\\d*\\.\\d+" ); // very simple floating point matching
int count = 0;
int pos = 0;
while ( pos >= 0 ) {
- pos = rx.search( str, pos );
- count++;
+ pos = rx.search( str, pos );
+ count++;
}
// pos will be 9, 14, 18 and finally 24; count will end up as 4.
\endcode
\sa searchRev() match() matchedLength() capturedTexts()
*/
// QChar versions
#ifdef QCHAR_SUPPORT
const QString makeString(const QChar *str)
{
// A sentinel value checked in case the QChar *ptr is never null terminated
- const uint MAXLENGTH=65535;
+ const uint MAXLENGTH=65535;
- const QChar *s=str;
- uint i=0;
- while(i < MAXLENGTH && *s != QChar::null) { i++;s++ ;}
+ const QChar *s=str;
+ uint i=0;
+ while(i < MAXLENGTH && *s != QChar::null) { i++;s++ ;}
return QString(str,i);
}
int QRegExp3::search(const QChar *str,int start)
{
- return search(makeString(str),start);
+ return search(makeString(str),start);
}
int QRegExp3::search(const QChar *str,int start) const
{
- return search(makeString(str),start);
+ return search(makeString(str),start);
}
int QRegExp3::searchRev(const QChar *str,int start)
{
- return searchRev(makeString(str),start);
+ return searchRev(makeString(str),start);
}
int QRegExp3::searchRev(const QChar *str,int start) const
{
- return searchRev(makeString(str),start);
+ return searchRev(makeString(str),start);
}
bool QRegExp3::exactMatch(const QChar *str)
{
- return exactMatch(makeString(str));
+ return exactMatch(makeString(str));
}
bool QRegExp3::exactMatch(const QChar *str) const
{
- return exactMatch(makeString(str));
+ return exactMatch(makeString(str));
}
#endif // QCHAR_SUPPORT
int QRegExp3::search( const QString& str, int start )
{
if ( start < 0 )
- start += str.length();
+ start += str.length();
#ifndef QT_NO_REGEXP_CAPTURE
priv->t = str;
priv->capturedCache.clear();
#endif
priv->captured = eng->match( str, start, priv->min, FALSE );
return priv->captured[0];
}
/*! \overload
This version does not set matchedLength(), capturedTexts() and friends.
*/
int QRegExp3::search( const QString& str, int start ) const
{
if ( start < 0 )
- start += str.length();
+ start += str.length();
return eng->match( str, start, priv->min, FALSE )[0];
}
/*!
Attempts to find a match backwards in \a str from position \a start. If
\a start is -1 (the default), the search starts at the last character; if -2,
at the next to last character; etc.
Returns the position of the first match, or -1 if there was no match.
You might prefer to use QString::findRev().
\sa search() matchedLength() capturedTexts()
*/
int QRegExp3::searchRev( const QString& str, int start )
{
if ( start < 0 )
- start += str.length();
+ start += str.length();
#ifndef QT_NO_REGEXP_CAPTURE
priv->t = str;
priv->capturedCache.clear();
#endif
if ( start < 0 || start > (int) str.length() ) {
- priv->captured.detach();
- priv->captured.fill( -1 );
- return -1;
+ priv->captured.detach();
+ priv->captured.fill( -1 );
+ return -1;
}
while ( start >= 0 ) {
- priv->captured = eng->match( str, start, priv->min, TRUE );
- if ( priv->captured[0] == start )
- return start;
- start--;
+ priv->captured = eng->match( str, start, priv->min, TRUE );
+ if ( priv->captured[0] == start )
+ return start;
+ start--;
}
return -1;
}
/*! \overload
This version does not set matchedLength(), capturedText() and friends.
*/
int QRegExp3::searchRev( const QString& str, int start ) const
{
if ( start < 0 )
- start += str.length();
+ start += str.length();
if ( start < 0 || start > (int) str.length() )
- return -1;
+ return -1;
while ( start >= 0 ) {
- if ( eng->match(str, start, priv->min, TRUE)[0] == start )
- return start;
- start--;
+ if ( eng->match(str, start, priv->min, TRUE)[0] == start )
+ return start;
+ start--;
}
return -1;
}
/*!
Returns the length of the last matched string, or -1 if there was no match.
\sa match() search()
*/
int QRegExp3::matchedLength()
{
return priv->captured[1];
}
#ifndef QT_NO_REGEXP_CAPTURE
/*!
Returns a list of the captured text strings.
The first string in the list is the entire matched string. Each
subsequent list element contains a string that matched a
(capturing) subexpression of the regexp.
For example:
\code
QRegExp3 rx( "(\\d+)(\\s*)(cm|inch(es)?)" );
int pos = rx.search( "Length: 36 inches" );
QStringList list = rx.capturedTexts();
// list is now ( "36 inches", "36", " ", "inches", "es" ).
\endcode
The above example also captures elements
that may be present but which we have no interest in. This problem
can be solved by using non-capturing parenthesis:
\code
QRegExp3 rx( "(\\d+)(?:\\s*)(cm|inch(?:es)?)" );
int pos = rx.search( "Length: 36 inches" );
QStringList list = rx.capturedTexts();
// list is now ( "36 inches", "36", "inches" ).
\endcode
Some regexps can match an indeterminate number of times. For example
if the input string is "Offsets: 12 14 99 231 7" and the regexp,
<tt>rx</tt>, is <b>(</b><b>\\</b><b>d+)+</b>, we would hope to get a
list of all the numbers matched. However, after calling
<tt>rx.search(str)</tt>, capturedTexts() will return the list ( "12",
"12" ), i.e. the entire match was "12" and the first subexpression
matched was "12". The correct approach is to use cap() in a
<a href="#cap_in_a_loop">loop</a>.
The order of elements in the string list is as follows. The first
element is the entire matching string. Each subsequent element
corresponds to the next capturing open left parenthesis. Thus
capturedTexts()[1] is the text of the first capturing parenthesis,
capturedTexts()[2] is the text of the second and so on (corresponding
to $1, $2 etc. in some other regexp languages).
\sa cap() pos()
*/
QStringList QRegExp3::capturedTexts()
{
if ( priv->capturedCache.isEmpty() ) {
- for ( int i = 0; i < (int) priv->captured.size(); i += 2 ) {
- QString m;
- if ( priv->captured[i + 1] == 0 )
- m = QString::fromLatin1( "" );
- else if ( priv->captured[i] >= 0 )
- m = priv->t.mid( priv->captured[i],
- priv->captured[i + 1] );
- priv->capturedCache.append( m );
- }
- priv->t = QString::null;
+ for ( int i = 0; i < (int) priv->captured.size(); i += 2 ) {
+ QString m;
+ if ( priv->captured[i + 1] == 0 )
+ m = QString::fromLatin1( "" );
+ else if ( priv->captured[i] >= 0 )
+ m = priv->t.mid( priv->captured[i],
+ priv->captured[i + 1] );
+ priv->capturedCache.append( m );
+ }
+ priv->t = QString::null;
}
return priv->capturedCache;
}
/*! Returns the text captured by the \a nth subexpression. The entire match
has index 0 and the parenthesised subexpressions have indices starting
from 1 (excluding non-capturing parenthesis).
\code
QRegExp3 rxlen( "(\\d+)(?:\\s*)(cm|inch)" );
int pos = rxlen.search( "Length: 189cm" );
if ( pos > -1 ) {
- QString value = rxlen.cap( 1 ); // "189"
- QString unit = rxlen.cap( 2 ); // "cm"
- // ...
+ QString value = rxlen.cap( 1 ); // "189"
+ QString unit = rxlen.cap( 2 ); // "cm"
+ // ...
}
\endcode
<a name="cap_in_a_loop">
Some patterns may lead to a number of matches which cannot be
determined in advance, for example:</a>
\code
QRegExp3 rx( "(\\d+)" );
str = "Offsets: 12 14 99 231 7";
QStringList list;
pos = 0;
while ( pos >= 0 ) {
- pos = rx.search( str, pos );
- if ( pos > -1 ) {
- list += rx.cap( 1 );
- pos += rx.matchedLength();
- }
+ pos = rx.search( str, pos );
+ if ( pos > -1 ) {
+ list += rx.cap( 1 );
+ pos += rx.matchedLength();
+ }
}
// list contains: ( "12", "14", "99", "231", "7" ).
\endcode
The order of elements matched by cap() is as follows. The first
element, cap( 0 ), is the entire matching string. Each subsequent
element corresponds to the next capturing open left parenthesis. Thus
cap( 1 ) is the text of the first capturing parenthesis, cap( 2 ) is
the text of the second and so on.
\sa search() pos() capturedTexts()
*/
QString QRegExp3::cap( int nth )
{
if ( nth < 0 || nth >= (int) priv->captured.size() / 2 )
- return QString::null;
+ return QString::null;
else
- return capturedTexts()[nth];
+ return capturedTexts()[nth];
}
/*! Returns the position of the \a nth captured text in the
searched string. If \a nth is 0 (the default), pos() returns the
position of the whole match.
Example:
\code
QRegExp3 rx( "/([a-z]+)/([a-z]+)" );
- rx.search( "Output /dev/null" ); // Returns 7 (position of /dev/null)
+ rx.search( "Output /dev/null" ); // Returns 7 (position of /dev/null)
rx.pos( 0 ); // Returns 7 (position of /dev/null)
rx.pos( 1 ); // Returns 8 (position of dev)
rx.pos( 2 ); // Returns 12 (position of null)
\endcode
Note that pos() returns -1 for zero-length matches. (For example, if
cap(4) would return an empty string, pos(4) returns -1.) This is due
to an implementation tradeoff.
\sa capturedTexts() cap()
*/
int QRegExp3::pos( int nth )
{
if ( nth < 0 || nth >= (int) priv->captured.size() / 2 )
- return -1;
+ return -1;
else
- return priv->captured[2 * nth];
+ return priv->captured[2 * nth];
}
#endif
void QRegExp3::compile( bool caseSensitive )
{
derefEngine( eng, priv->rxpattern );
#ifndef QT_NO_REGEXP_WILDCARD
if ( priv->wc )
- priv->rxpattern = wc2rx( priv->pattern );
+ priv->rxpattern = wc2rx( priv->pattern );
else
#endif
- priv->rxpattern = priv->pattern.isNull() ? QString::fromLatin1( "" )
- : priv->pattern;
+ priv->rxpattern = priv->pattern.isNull() ? QString::fromLatin1( "" )
+ : priv->pattern;
eng = newEngine( priv->rxpattern, caseSensitive );
#ifndef QT_NO_REGEXP_CAPTURE
priv->t = QString::null;
priv->capturedCache.clear();
#endif
priv->captured.detach();
priv->captured.fill( -1, 2 + 2 * eng->numCaptures() );
}