[Pinfo-devel] r146 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Fri Sep 2 09:42:17 UTC 2005
Author: neroden-guest
Date: 2005-09-02 09:42:17 +0000 (Fri, 02 Sep 2005)
New Revision: 146
Modified:
pinfo/branches/cxx/src/initializelinks.cxx
pinfo/branches/cxx/src/initializelinks.h
pinfo/branches/cxx/src/manual.cxx
Log:
Arrrr. Finish converting findurlend and findemailstart users to std::string.
Modified: pinfo/branches/cxx/src/initializelinks.cxx
===================================================================
--- pinfo/branches/cxx/src/initializelinks.cxx 2005-09-02 08:52:46 UTC (rev 145)
+++ pinfo/branches/cxx/src/initializelinks.cxx 2005-09-02 09:42:17 UTC (rev 146)
@@ -175,12 +175,12 @@
* Moves you to the beginning of username in email address. If username has
* length=0, NULL is returned.
*/
-char *
-findemailstart(char *str)
+const char *
+findemailstart(const char *str)
{
- char *allowedchars = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-_/~.%=|:";
- char *at = strchr(str, '@');
- char *emailstart = 0;
+ const char *allowedchars = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-_/~.%=|:";
+ const char *at = strchr(str, '@');
+ const char *emailstart = 0;
if (at)
{
emailstart = str;
@@ -203,11 +203,23 @@
return 0;
}
+string::size_type
+findemailstart(string str, string::size_type pos) {
+ /* Currently a wrapper (sigh, FIXME) */
+ const char * foo = str.substr(pos).c_str();
+ const char * bar = findemailstart(foo);
+ if (bar == NULL) {
+ return string::npos;
+ } else {
+ return string::size_type(bar - foo);
+ }
+}
+
void
initializelinks(char *line1, char *line2, int line)
{
char *tmp;
- char *notestart = 0, *urlstart = 0, *urlend = 0;
+ char *notestart = 0;
char *quotestart = 0, *quoteend = 0;
char *buf = (char*)xmalloc(strlen(line1) + strlen(line2) + 1);
int changed;
@@ -219,12 +231,12 @@
if (strlen(line1))
buf[strlen(line1) - 1] = ' '; /* replace trailing '\n' with ' ' */
strcat(buf, line2);
+
/******************************************************************************
* First scan for some highlights ;) -- words enclosed with quotes *
******************************************************************************/
quoteend = buf;
- do
- {
+ do {
changed = 0;
if ((quotestart = strchr(quoteend, '`')) != NULL) /* find start of quoted text */
{
@@ -260,24 +272,25 @@
}
}
}
- }
- while (changed);
+ } while (changed);
+
/******************************************************************************
* Look for e-mail url's *
******************************************************************************/
- urlend = line1;
- do
- {
+ string url_tmpstr = line1;
+ string::size_type urlstart = 0;
+ string::size_type urlend = 0;
+ do {
changed = 0;
- if ((urlstart = findemailstart(urlend)) != NULL)
+ if ((urlstart = findemailstart(url_tmpstr, urlend)) != string::npos)
{
- urlend = findurlend(urlstart); /* always successful */
+ urlend = findurlend(url_tmpstr, urlstart); /* always successful */
HyperObject my_ho;
my_ho.line = line;
- my_ho.col = calculate_len(line1, urlstart);
+ my_ho.col = calculate_len(line1, line1 + urlstart);
my_ho.breakpos = -1;
my_ho.type = 6;
- my_ho.node.assign(urlstart, urlend - urlstart);
+ my_ho.node = url_tmpstr.substr(urlstart, urlend - urlstart);
my_ho.file = "";
my_ho.tagtableoffset = -1;
if (my_ho.node.find('.') == string::npos) {
@@ -287,9 +300,8 @@
}
changed = 1;
}
+ } while (changed);
- }
- while (changed);
/******************************************************************************
* First try to scan for menu. Use as many security mechanisms, as possible *
******************************************************************************/
@@ -578,6 +590,7 @@
if ((notestart = strstr(notestart + 6, "*note")) != NULL)
goto handlenote;
}
+
/******************************************************************************
* Try to scan for some url-like objects in single line; mainly *
* http://[address][space|\n|\t] *
@@ -585,31 +598,35 @@
* username at something.else[space|\n|\t] *
*****************************************************************************/
/* http:// */
- urlend = line1;
- while ((urlstart = strstr(urlend, "http://")) != NULL)
+ url_tmpstr = line1;
+ urlstart = 0;
+ urlend = 0;
+ while ( (urlstart = url_tmpstr.find("http://", urlend)) != string::npos)
{
- urlend = findurlend(urlstart); /* always successful */
+ urlend = findurlend(url_tmpstr, urlstart); /* always successful */
HyperObject my_ho;
my_ho.line = line;
- my_ho.col = calculate_len(line1, urlstart);
+ my_ho.col = calculate_len(line1, line1 + urlstart);
my_ho.breakpos = -1;
my_ho.type = 4;
- my_ho.node.assign(urlstart, urlend - urlstart);
+ my_ho.node = url_tmpstr.substr(urlstart, urlend - urlstart);
my_ho.file = "";
my_ho.tagtableoffset = -1;
hyperobjects.push_back(my_ho);
}
/* ftp:// */
- urlend = line1;
- while ((urlstart = strstr(urlend, "ftp://")) != NULL)
+ url_tmpstr = line1;
+ urlstart = 0;
+ urlend = 0;
+ while ( (urlstart = url_tmpstr.find("ftp://", urlend)) != string::npos)
{
- urlend = findurlend(urlstart); /* always successful */
+ urlend = findurlend(url_tmpstr, urlstart); /* always successful */
HyperObject my_ho;
my_ho.line = line;
- my_ho.col = calculate_len(line1, urlstart);
+ my_ho.col = calculate_len(line1, line1 + urlstart);
my_ho.breakpos = -1;
my_ho.type = 5;
- my_ho.node.assign(urlstart, urlend - urlstart);
+ my_ho.node = url_tmpstr.substr(urlstart, urlend - urlstart);
my_ho.file = "";
my_ho.tagtableoffset = -1;
hyperobjects.push_back(my_ho);
Modified: pinfo/branches/cxx/src/initializelinks.h
===================================================================
--- pinfo/branches/cxx/src/initializelinks.h 2005-09-02 08:52:46 UTC (rev 145)
+++ pinfo/branches/cxx/src/initializelinks.h 2005-09-02 09:42:17 UTC (rev 146)
@@ -24,15 +24,16 @@
/* initializes node links. */
void initializelinks (char *line1, char *line2, int line);
/*
- * scans for url end in given url-string.
- * returns a pointer to the found place.
+ * scans for url end in given url-string (from pos).
+ * returns index of found place.
*/
-char *findurlend (char *str);
std::string::size_type findurlend (std::string str,
std::string::size_type pos = 0);
-/* scans for the beginning of username. Returns a pointer to it. */
-char *findemailstart (char *str);
+/* scans for the beginning of username. Returns its index. */
+std::string::size_type findemailstart (std::string str,
+ std::string::size_type pos = 0);
+
/*
* calculate length of visible part of string ('\t' included) between start and
* end. Returns length.
Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx 2005-09-02 08:52:46 UTC (rev 145)
+++ pinfo/branches/cxx/src/manual.cxx 2005-09-02 09:42:17 UTC (rev 146)
@@ -547,59 +547,61 @@
void
man_initializelinks(char *tmp, int carry)
{
+ vector<manuallink>::size_type initialManualLinks = manuallinks.size();
/******************************************************************************
* handle url refrences *
*****************************************************************************/
- char *urlstart, *urlend;
- urlend = tmp;
- vector<manuallink>::size_type initialManualLinks = manuallinks.size();
-
- char* crap = tmp;
- while ((urlstart = strstr(urlend, "http://")) != NULL)
+ string tmpstr = tmp;
+ string::size_type urlstart = 0;
+ string::size_type urlend = 0;
+ while ((urlstart = tmpstr.find("http://", urlend)) != string::npos)
{
- /* always successfull */
- urlend = findurlend(urlstart);
+ urlend = findurlend(tmpstr, urlstart); /* always successful */
manuallink my_link;
my_link.line = ManualLines;
- my_link.col = urlstart - tmp;
+ my_link.col = urlstart;
my_link.section = "HTTPSECTION";
my_link.section_mark = HTTPSECTION;
- my_link.name.assign(urlstart, urlend - urlstart - 1);
+ my_link.name = tmpstr.substr(urlstart, urlend - urlstart - 1);
if (ishyphen(my_link.name[urlend - urlstart - 1]))
my_link.carry = 1;
else
my_link.carry = 0;
manuallinks.push_back(my_link);
}
- urlend = tmp;
- while ((urlstart = strstr(urlend, "ftp://")) != NULL)
+
+ tmpstr = tmp;
+ urlstart = 0;
+ urlend = 0;
+ while ((urlstart = tmpstr.find("ftp://", urlend)) != string::npos)
{
- /* always successfull */
- urlend = findurlend(urlstart);
+ urlend = findurlend(tmpstr, urlstart); /* always successful */
manuallink my_link;
my_link.line = ManualLines;
- my_link.col = urlstart - tmp;
+ my_link.col = urlstart;
my_link.section = "FTPSECTION";
my_link.section_mark = FTPSECTION;
- my_link.name.assign(urlstart, urlend - urlstart - 1);
+ my_link.name = tmpstr.substr(urlstart, urlend - urlstart - 1);
if (ishyphen(my_link.name[urlend - urlstart - 1]))
my_link.carry = 1;
else
my_link.carry = 0;
manuallinks.push_back(my_link);
}
- urlend = tmp;
- while ((urlstart = findemailstart(urlend)) != NULL)
+
+ tmpstr = tmp;
+ urlstart = 0;
+ urlend = 0;
+ while ((urlstart = findemailstart(tmpstr, urlend)) != string::npos)
{
- /* always successfull */
- urlend = findurlend(urlstart);
+ urlend = findurlend(tmpstr, urlstart); /* always successful */
manuallink my_link;
my_link.line = ManualLines;
- my_link.col = urlstart - tmp;
+ my_link.col = urlstart;
my_link.section = "MAILSECTION";
my_link.section_mark = MAILSECTION;
- my_link.name.assign(urlstart, urlend - urlstart - 1);
+ my_link.name = tmpstr.substr(urlstart, urlend - urlstart - 1);
if (ishyphen(my_link.name[urlend - urlstart - 1]))
my_link.carry = 1;
else
@@ -1658,7 +1660,9 @@
while (isspace(*wsk))
wsk++;
/* find the end of url */
- wskend = findurlend(wsk);
+ string temp_string = wsk;
+ string::size_type wskend_idx = findurlend(temp_string);
+ wskend = wsk + wskend_idx;
/* add end of string, and print */
*wskend = 0;
if (wsk-tmpstr<manualcol)
More information about the Pinfo-devel
mailing list