Update of /cvsroot/mahogany/M/src/util
In directory usw-pr-cvs1:/tmp/cvs-serv6865/src/util
Modified Files:
matchurl.cpp
Log Message:
fixed a signed/unsigned warning and reformatted the code
Index: matchurl.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/util/matchurl.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -b -u -2 -r1.14 -r1.15
--- matchurl.cpp 3 May 2002 23:17:08 -0000 1.14
+++ matchurl.cpp 4 May 2002 11:46:32 -0000 1.15
@@ -30,17 +30,15 @@
// ----------------------------------------------------------------------------
-// TODO: translate Xavier's comments and variable names to English
-
/// KeywordDetectorCell represents a single keyword letter with links from it
-class KeywordDetectorCell {
-
- friend class KeywordDetector;
-
+class KeywordDetectorCell
+{
public:
KeywordDetectorCell(char c) :
_c(c), _son(NULL), _brother(NULL), _isKey(0), _back(NULL) {}
- ~KeywordDetectorCell() {
- if (_c != '\000') {
+ ~KeywordDetectorCell()
+ {
+ if (_c != '\000')
+ {
delete _son;
delete _brother;
@@ -60,4 +58,6 @@
void computeBackArcs(KeywordDetectorCell* root,
KeywordDetectorCell* parentBack);
+
+ friend class KeywordDetector;
};
@@ -66,13 +66,11 @@
* Keywords scanner
*/
-class KeywordDetector {
+class KeywordDetector
+{
public:
KeywordDetector() : _root(NULL) { }
- ~KeywordDetector() {
- delete _root;
- }
+ ~KeywordDetector() { delete _root; }
public:
-
/// Adds a new keyword to the list of detected keywords
void addNewKeyword(const char* key);
@@ -107,5 +105,4 @@
}
-
private:
void addNewKeyword(const char* key,
@@ -140,5 +137,6 @@
// ============================================================================
-void KeywordDetector::addNewKeyword(const char* key) {
+void KeywordDetector::addNewKeyword(const char* key)
+{
//
// Ajout d'un mot-clef dans l'arbre
@@ -151,6 +149,8 @@
void KeywordDetector::addNewKeyword(const char* key,
KeywordDetectorCell* current,
- int toBeAdded) {
- if (! current) {
+ int toBeAdded)
+{
+ if (! current)
+ {
// This is the first keyword inserted
// We must create adn save the root of the tree
@@ -160,12 +160,17 @@
return;
}
- if (current->_c == key[0]) {
+
+ if (current->_c == key[0])
+ {
// The key is correct: this is the correct cell
- if (key[1] == '\000') {
+ if (key[1] == '\000')
+ {
// And we have reached the end of a keyword
// Donc la cellule courante marque la fin
// d'un mot-clef
current->_isKey = toBeAdded;
- } else {
+ }
+ else
+ {
// The keyword to add (or remove) is not finished
if (! current->_son) {
@@ -176,11 +181,15 @@
addNewKeyword(key+1, current->_son);
}
- } else {
+ }
+ else
+ {
// This is not the correct cell
- if (! current->_brother) {
+ if (! current->_brother)
+ {
// No brother. Let's create one
KeywordDetectorCell* newCell = new KeywordDetectorCell(key[0]);
current->_brother = newCell;
}
+
addNewKeyword(key, current->_brother);
}
@@ -188,12 +197,18 @@
-int KeywordDetector::scanAtStart(const char* toBeScanned, KeywordDetectorCell*
current,
- int longueurDejaVue, int lngDernierTrouve) {
- if (! current) {
+int
+KeywordDetector::scanAtStart(const char* toBeScanned,
+ KeywordDetectorCell* current,
+ int longueurDejaVue,
+ int lngDernierTrouve)
+{
+ if (! current)
return lngDernierTrouve;
- }
- if (current->_c == toBeScanned[0]) {
+
+ if (current->_c == toBeScanned[0])
+ {
// This is the correct cell
- if (current->_isKey == 1) {
+ if (current->_isKey == 1)
+ {
// And this is the end of a keyword
// let's try to find a longer one, but do
@@ -204,17 +219,24 @@
longueurDejaVue+1,
longueurDejaVue+1);
- } else {
+ }
+ else
+ {
// This is not the end of a keyword
// Go on
- assert(current->_son);
+ CHECK( current->_son, -1, "current cell must have a son" );
return scanAtStart(toBeScanned+1, current->_son, longueurDejaVue+1,
lngDernierTrouve);
}
- } else {
+ }
+ else
+ {
// Not a correct cell
- if (! current->_brother) {
+ if (! current->_brother)
+ {
// And no more cell. Let's return the length
// we may have already found
return lngDernierTrouve;
- } else {
+ }
+ else
+ {
// There is another cell to try
return scanAtStart(toBeScanned, current->_brother, longueurDejaVue,
lngDernierTrouve);
@@ -224,19 +246,23 @@
-
-
-int KeywordDetector::scanAtStart(const char* toBeScanned) {
+int KeywordDetector::scanAtStart(const char* toBeScanned)
+{
return scanAtStart(toBeScanned, _root, 0, 0);
}
-int KeywordDetector::scan(const char* toBeScanned, int& lng, KeywordDetectorCell*
current) {
+int KeywordDetector::scan(const char* toBeScanned,
+ int& lng, KeywordDetectorCell* current)
+{
int currentPosition = 0;
lng = 0;
bool atRootLevel = true;
- while (toBeScanned[0]) {
- if (current->_c == toBeScanned[0]) {
+ while (toBeScanned[0])
+ {
+ if (current->_c == toBeScanned[0])
+ {
// This is the correct cell
- if (current->_isKey == 1) {
+ if (current->_isKey == 1)
+ {
// And the end of a keyword.
// let's try to find a longer one, but do
@@ -249,8 +275,10 @@
lng+1);
return currentPosition;
- } else {
+ }
+ else
+ {
// This is not the end of a keyword
// Go on
- assert(current->_son);
+ CHECK( current->_son, -1, "current cell must have a son" );
current = current->_son;
atRootLevel = false;
@@ -258,10 +286,14 @@
toBeScanned = toBeScanned + 1;
}
- } else {
+ }
+ else
+ {
// Not a correct cell
current = current->_brother;
- if (!current) {
+ if (!current)
+ {
current = _root;
- if (atRootLevel) {
+ if (atRootLevel)
+ {
toBeScanned++;
if ( !lng )
@@ -271,9 +303,11 @@
currentPosition = currentPosition + lng;
lng = 0;
- } else if (current->_c == '\000') {
+ }
+ else if (current->_c == '\000')
+ {
// This is a 'back-link'
currentPosition = currentPosition + lng - current->_isKey;
lng = current->_isKey;
- assert (lng > 0);
+ ASSERT_MSG( lng > 0, "length must be non 0" );
current = current->_son;
}
@@ -284,16 +318,23 @@
}
-KeywordDetectorCell* KeywordDetectorCell::computeBackArc(KeywordDetectorCell* root,
- KeywordDetectorCell*
parentBack) {
- assert(parentBack == 0 || parentBack->_c == '\000');
+KeywordDetectorCell *
+KeywordDetectorCell::computeBackArc(KeywordDetectorCell* root,
+ KeywordDetectorCell* parentBack)
+{
+ ASSERT_MSG(parentBack == 0 || parentBack->_c == '\000',
+ "logic error in KeywordDetectorCell?");
+
KeywordDetectorCell* back = 0;
KeywordDetectorCell* current = 0;
int backLevel = 0;
- if (! parentBack) {
+ if (! parentBack)
+ {
// Parent node has no back arc. So we look for
// nextLetter in root and its siblings
current = root;
backLevel = 1;
- } else {
+ }
+ else
+ {
// Parent has a back node. So we look for nextLetter
// in *the sons* of this back node
@@ -301,22 +342,31 @@
backLevel = parentBack->_isKey + 1;
}
- while (current) {
- if (current->_c == _c) {
+
+ while (current)
+ {
+ if (current->_c == _c)
+ {
back = current;
break;
}
+
current = current->_brother;
}
- if (current) {
+
+ if (current)
+ {
// We have found our back node
// Find our last son
KeywordDetectorCell* lastSon = _son;
+
// There must be a son, otherwise the current node would be a keyword
// and there is no need for a back node
- assert(lastSon);
- while (lastSon->_brother) {
+ CHECK(lastSon, 0, "node with a back link must have a son");
+
+ while (lastSon->_brother)
+ {
lastSon = lastSon->_brother;
}
- assert(! lastSon->_brother);
+
// A cell with key '\000' is points to the back node
KeywordDetectorCell* newCell = new KeywordDetectorCell('\000');
@@ -326,23 +376,31 @@
return newCell;
}
+
return 0;
}
-void KeywordDetectorCell::computeBackArcs(KeywordDetectorCell* root,
- KeywordDetectorCell* parentBack) {
+void
+KeywordDetectorCell::computeBackArcs(KeywordDetectorCell* root,
+ KeywordDetectorCell* parentBack)
+{
KeywordDetectorCell* parent = this;
bool onRootLevel = (parent == root ? true : false);
- while (parent) {
- if (parent->_c == '\000') {
+ while (parent)
+ {
+ if (parent->_c == '\000')
break;
- }
+
KeywordDetectorCell* back = 0;
- if (! (onRootLevel || parent->_isKey)) {
+ if (! (onRootLevel || parent->_isKey))
+ {
back = parent->computeBackArc(root, parentBack);
}
+
KeywordDetectorCell* son = parent->_son;
- if (son) {
+ if (son)
+ {
son->computeBackArcs(root, back);
}
+
parent = parent->_brother;
}
@@ -499,5 +557,5 @@
// positives so consider that only "long" URLs are wrapped where long
// URLs are defined as the ones containing the CGI script parameters
- if ( strcspn(start + len, "?&\r") == p - start - len )
+ if ( strcspn(start + len, "?&\r") == (size_t)(p - start - len) )
{
// no CGI parameters, suppose it can't wrap
_______________________________________________________________
Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates