Home » Developing U++ » U++ Developers corner » Pop3 class and reference examples for U++
Re: Pop3 class and reference examples for U++ [message #42948 is a reply to message #42698] |
Wed, 16 April 2014 03:00 |
Oblivion
Messages: 1093 Registered: August 2007
|
Senior Contributor |
|
|
Hello Mirek,
I see that you recently added ParseMessageIDs() method to the InetMessage class.
The code block in that function is something I encounter often. Especially when parsing some text (you can even see it in the Pop3::GetTimestamp()).
Maybe we should put that code under String utilities and change the code accordingly?
So I wrote the following Slice() functions which you can also come by in some other C++/Java frameworks.
int Slice(const String& s, String& d, const String& delim1, const String& delim2, int pos = 0)
{
int b = -1, e = -1;
if((b = s.Find(delim1, pos)) == -1 || (e = s.Find(delim2, b += delim1.GetLength())) == -1)
return -1;
d = s.Mid(b, e - b);
return e += delim2.GetLength();
}
int Slice(const WString& s, WString& d, const WString& delim1, const WString& delim2, int pos = 0)
{
int b = -1, e = -1;
if((b = s.Find(delim1, pos)) == -1 || (e = s.Find(delim2, b += delim1.GetLength())) == -1)
return -1;
d = s.Mid(b, e - b);
return e += delim2.GetLength();
}
int Slice(const String& s, String& d, int delim1, int delim2, int pos = 0)
{
int b = -1, e = -1;
if((b = s.Find(delim1, pos)) == -1 || (e = s.Find(delim2, ++b)) == -1)
return -1;
d = s.Mid(b, e - b);
return ++e;
}
int Slice(const WString& s, WString& d, int delim1, int delim2, int pos = 0)
{
int b = -1, e = -1;
if((b = s.Find(delim1, pos)) == -1 || (e = s.Find(delim2, ++b)) == -1)
return -1;
d = s.Mid(b, e - b);
return ++e;
}
String Slice(const String& s, const String& delim1, const String& delim2)
{
String r;
return (Slice(s, r, delim1, delim2) == -1) ? String::GetVoid() : r;
}
WString Slice(const WString& s, const WString& delim1, const WString& delim2)
{
WString r;
return (Slice(s, r, delim1, delim2) == -1) ? WString::GetVoid() : r;
}
String Slice(const String& s, int delim1, int delim2)
{
String r;
return (Slice(s, r, delim1, delim2) == -1) ? String::GetVoid() : r;
}
WString Slice(const WString& s, int delim1, int delim2)
{
WString r;
return (Slice(s, r, delim1, delim2) == -1) ? WString::GetVoid() : r;
}
They are really useful for parsing text. I already patched my local copy of upp (with its api reference doc in "String utility functions" section).
By the way, I can upload the patched files if you have time to review them and also approve them.
Regards.
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 16 April 2014 14:28] Report message to a moderator
|
|
|
|
|
Pop3 class and reference examples for U++
By: Oblivion on Fri, 17 January 2014 01:49
|
|
|
Re: Pop3 class and reference examples for U++
By: koldo on Fri, 17 January 2014 08:12
|
|
|
Re: Pop3 class and reference examples for U++
By: mirek on Fri, 17 January 2014 08:27
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Fri, 17 January 2014 12:00
|
|
|
Re: Pop3 class and reference examples for U++
By: mirek on Tue, 25 March 2014 10:07
|
|
|
Re: Pop3 class and reference examples for U++
By: mirek on Wed, 26 March 2014 10:34
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Wed, 26 March 2014 12:37
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Wed, 26 March 2014 18:31
|
|
|
Re: Pop3 class and reference examples for U++
By: mirek on Thu, 27 March 2014 08:45
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Thu, 27 March 2014 15:24
|
|
|
Re: Pop3 class and reference examples for U++
By: mirek on Thu, 27 March 2014 15:38
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Sun, 30 March 2014 01:48
|
|
|
Re: Pop3 class and reference examples for U++
By: mirek on Sun, 30 March 2014 09:29
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Thu, 10 April 2014 01:24
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Thu, 10 April 2014 16:14
|
|
|
Re: Pop3 class and reference examples for U++
By: mirek on Mon, 28 April 2014 17:48
|
|
|
Re: Pop3 class and reference examples for U++
By: Oblivion on Wed, 16 April 2014 03:00
|
Goto Forum:
Current Time: Mon Apr 29 00:01:07 CEST 2024
Total time taken to generate the page: 0.04238 seconds
|