473,657 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c++ code snippets site

Hi

I'd like to place this code to C++ code snippets site.
Does anyone know about where is could be?

Andrei Smirnov

=============== =============== =========
//
// example of how to strip std C++ string of empty symbols
// in header and trailer
//

#include <iostream>
#include <string>
using namespace std;

void string_strip(st ring* s)
{
static const char* empties = " \t\n\r";
int b = s->find_first_not _of(empties);
if (b == -1) {
*s = string();
return;
}
int e = s->find_last_not_ of(empties);
*s = string(*s, b, e + 1 - b);
}

int main()
{
string ss[] = {
" Hi my friend\t \n",
"",
" \t hi \n\t\r",
"HI ",
"SSSSSS",
" Bye"
};
for (int i = 0; i < sizeof(ss) / sizeof(ss[0]); ++i) {
string s = ss[i];
string_strip(&s );
cerr << "'" << s << "'" << endl;
}
}

Jul 22 '05 #1
8 2356
as************* ***@yahoo.com wrote:
I'd like to place this code to C++ code snippets site.
Why? You posted it here, it should soon be available on the Google
newsgroup archives site...
[...]

Jul 22 '05 #2
<as************ ****@yahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Hi

I'd like to place this code to C++ code snippets site.
Why? What does it do that you think others would
find useful? It's just plain wrong.
Does anyone know about where is could be?
I'm not sure which site you mean. I do know of one called
www.snippets.org

You can visit there to find out if/how code submissions
are done.

=============== =============== =========
//
// example of how to strip std C++ string of empty symbols
// in header and trailer
//

#include <iostream>
#include <string>
using namespace std;

void string_strip(st ring* s)
Why a pointer? Why not a reference?
{
static const char* empties = " \t\n\r";
int b = s->find_first_not _of(empties);
The return type of 'std::string::f ind_first_not_o f()' is
'std::string::s ize_type', not 'int'. This is the case
for all the string's 'find' functions.
if (b == -1) {
Why are you checking for -1. If 'find_first_not _of()' does
not find anything, it returns the value 'std::string::n pos',
whose value is implementation defined. It could be -1, it
could be some other value.
*s = string();
return;
}
int e = s->find_last_not_ of(empties);
Again, wrong type being used to store return value.
*s = string(*s, b, e + 1 - b);
}

int main()
{
string ss[] = {
" Hi my friend\t \n",
"",
" \t hi \n\t\r",
"HI ",
"SSSSSS",
" Bye"
};
Why use an array when you have the much safer and easier
to use containers, e.g. vector?
for (int i = 0; i < sizeof(ss) / sizeof(ss[0]); ++i) {
string s = ss[i];
string_strip(&s );
cerr << "'" << s << "'" << endl;
}
}


I very much doubt the above code would be accepted by a
site offering code snippets. It's got many problems.

If you scan the archives of this group, you'll find several
much superior solutions than yours.

-Mike
Jul 22 '05 #3
Mike Wahler wrote:
<as************ ****@yahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I'd like to place this code to C++ code snippets site.
Why? What does it do that you think others would
find useful? It's just plain wrong.


it has some features to tease geeks like you :)
Does anyone know about where is could be?


I'm not sure which site you mean. I do know of one called
www.snippets.org


this is useless crap indeed. my favorite was 'portable string class' :)
=============== =============== =========
//
// example of how to strip std C++ string of empty symbols
// in header and trailer
//

#include <iostream>
#include <string>
using namespace std;

void string_strip(st ring* s)


Why a pointer? Why not a reference?


not of you business. i like pointers, there were here before stroustrup
decided to win battle with fortran and introduced refs solely to
support
operations overloading (unfortunately this created good breed
environment
for people who tread ANSI C++ standard as bible).
{
static const char* empties = " \t\n\r";
int b = s->find_first_not _of(empties);
The return type of 'std::string::f ind_first_not_o f()' is
'std::string::s ize_type', not 'int'. This is the case
for all the string's 'find' functions.


could you give me the list of compilers/platforms where is matters?
if (b == -1) {
Why are you checking for -1. If 'find_first_not _of()' does
not find anything, it returns the value 'std::string::n pos',
whose value is implementation defined. It could be -1, it
could be some other value.


could you imagine any other value than -1. think hard...
.....

int main()
{
string ss[] = {
" Hi my friend\t \n",
"",
" \t hi \n\t\r",
"HI ",
"SSSSSS",
" Bye"
};


Why use an array when you have the much safer and easier
to use containers, e.g. vector?


because i like everything unsafe and hard. this is my choice.
for (int i = 0; i < sizeof(ss) / sizeof(ss[0]); ++i) {
string s = ss[i];
string_strip(&s );
cerr << "'" << s << "'" << endl;
}
}

I very much doubt the above code would be accepted by a
site offering code snippets. It's got many problems.

it was accepted by usenet already without asking you.
If you scan the archives of this group, you'll find several
much superior solutions than yours.
could you be more specific? i just want the function which strips
spaces
out of my string. i don't need superior solution of this apparently
'very
big' problem.

-Mike


Andrei

PS: if you are so cool with standard can you tell me what virse 2 of
12.1.5
said. you've got thirty seconds, otherwise you are not cool. time is
running...

Jul 22 '05 #4
that was precisely the idea

Andrei

Jul 22 '05 #5
as************* ***@yahoo.com wrote:
[... insulting and rude response snipped ...]


Perhaps you could be a bit less "cool" and a bit more tactful.
Just a thought. More like dream, probably.

Spend more time lurking around instead of suggesting "solutions"
and insulting regulars, and perhaps everybody is going to have
even more pleasant time visiting comp.lang.c++.
Jul 22 '05 #6

<as************ ****@yahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Mike Wahler wrote:
<as************ ****@yahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I'd like to place this code to C++ code snippets site.
Why? What does it do that you think others would
find useful? It's just plain wrong.


it has some features to tease geeks like you :)


Which are?
Does anyone know about where is could be?
I'm not sure which site you mean. I do know of one called
www.snippets.org


this is useless crap indeed.

Usefulness is in the eye of the beholder. I for one, have
found some of the code there useful for learning purposes.
If others have found it useless, that doesn't change what
it's done for me.
my favorite was 'portable string class' :)
=============== =============== =========
//
// example of how to strip std C++ string of empty symbols
// in header and trailer
//

#include <iostream>
#include <string>
using namespace std;

void string_strip(st ring* s)
Why a pointer? Why not a reference?


not of you business.
i like pointers,


Why? IMO they are one of the major sources of bugs.
there were here before stroustrup
decided
So you seem to be basing your claim of their superiority
over references upon their tenure. I find that to be
very poor logic. Abacuses have been around for thousands
of years. Are they superior to the modern digital computer?
to win battle with fortran
Perhaps you should read some of Stroustrup's writings (e.g.
his "Design and Evolution of C++") before you try to put words
into his mouth.
and introduced refs solely to
support
operations overloading
Repeat my last paragraph above.
(unfortunate ly this created good breed
environment
for people who tread ANSI C++ standard as bible).
I treat the C++ standard for what it is: the single authoritative
definition of the C++ language. I exploit the guarantees it
grants to me regarding my C++ programs, when translated by
implementations which adhere to it.

{
static const char* empties = " \t\n\r";
int b = s->find_first_not _of(empties);


The return type of 'std::string::f ind_first_not_o f()' is
'std::string::s ize_type', not 'int'. This is the case
for all the string's 'find' functions.


could you give me the list of compilers/platforms where is matters?


No need. I have the language standard to guarantee behavior
(if I follow the rules.) One such rule is that the 'std::string'
'find' functions report 'not found' with a value denoted by
the expression 'std::string::n pos'. No other value is given
this guarantee, nor is there any guranteee of a particular
actual value for 'npos'.
if (b == -1) {


Why are you checking for -1. If 'find_first_not _of()' does
not find anything, it returns the value 'std::string::n pos',
whose value is implementation defined. It could be -1, it
could be some other value.


could you imagine any other value than -1. think hard...


Any negative value, or any positive value outside the
range of 'std::string::s ize_type'.

....

int main()
{
string ss[] = {
" Hi my friend\t \n",
"",
" \t hi \n\t\r",
"HI ",
"SSSSSS",
" Bye"
};
Why use an array when you have the much safer and easier
to use containers, e.g. vector?


because i like everything unsafe and hard. this is my choice.


So be it. I'll add your name to my 'no-hire' list. :-)
for (int i = 0; i < sizeof(ss) / sizeof(ss[0]); ++i) {
string s = ss[i];
string_strip(&s );
cerr << "'" << s << "'" << endl;
}
}

I very much doubt the above code would be accepted by a
site offering code snippets. It's got many problems.


it was accepted by usenet already without asking you.


Usenet is not a person which can make decisions or 'accept'
or 'reject' something. It's just a 'place'. A tree will
'accept' me shooting it with a shotgun, that doesn't stop
such an action from being detrimental to the tree.
If you scan the archives of this group, you'll find several
much superior solutions than yours.


could you be more specific?


Um, no I won't do your research for you. I've already pointed
out a promising place for you to look.
i just want the function which strips
spaces
out of my string.
And there are many which have already been posted to
Usenet (and the web) many times.
i don't need superior solution
Yet you claim to have created one, but have failed
to demonstrate its superiority.
of this apparently
'very
big' problem.
I don't find it a big problem at all. I've long ago solved
it, in many different languages.
-Mike


Andrei

PS: if you are so cool with standard


I'm not, and never have claimed to be 'cool with standard'.
However I do possess a copy of the ISO standard for C++, and
refer to it when I need to know a conclusive answer to a
question about C++.
can you tell me what virse 2 of
12.1.5
said.
That one's easy. It doesn't say anything, because it does not exist.
you've got thirty seconds,
I'll take as much time as I need, thank you, until such time
as you're paying me to do things for you.
otherwise you are not cool.
My goal is not and never has been to be 'cool'.
time is
running...


Always has been, always will. So what?
OK, so you're 'cool'. I'm productive. That's the way I like it.

-Mike
Jul 22 '05 #7
Mike Wahler wrote:

OK, so you're 'cool'. I'm productive. That's the way I like it.


Gotta add that to my .sig. Well, when I've got a .sig again...

:-)
Jul 22 '05 #8
Hi Andrei,
you could always start a project on www.codeproject.com or
www.developersex.com if you feel the need to share what you have
written with the world..:-)

If you actually want to build something significant and have other
people contribute you could start an open source project on
www.sourceforge.net.

Best Regards

Peter Nolan

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1673
by: juglesh | last post by:
howdy, I am using this code library thing: http://sourceforge.net/projects/php-csl/ http://www.php-csl.com/snippets/ and had an idea. I was thinking about keeping a bunch of functions in the root dir of my server, so I can re-use my code from any of my websites without having to copy each func or code into the current site that i’m working on. So, It’d be kinda like PEAR, you’d just go: Code:
2
2006
by: - Steve - | last post by:
I'm working on my asp.net site and I'm wondering what the best way to reuse little snippets of code is? Right now I have a Class in it's own cs file that I call Snippets. Then when I want to use something in there (like for example I have Snippets.Logout()) I do the following. Snippets snips = new Snippets(); snips.LogOut();
18
3150
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the ASP.Net process is recycled? This code executes pretty frequently (maybe 4 times per transaction) and...
19
2264
by: Swaregirl | last post by:
Hello, I would like to build a website using ASP.NET. I would like website visitors to be able to download code that I would like to make available to them and that would be residing on my personal server. Are there any code samples or books that someone can recommend so that I can implement this. I would prefer VB.NET code, but I am willing to convert from C# if necessary.
13
2307
by: frk.won | last post by:
I am interested in learning how to use the VS 2005 code snippets. However, I wish to know what are the best ways to source control the code snippets? Are there any source safe/subversion add-ons for this purpose? If not, any urls which demonstrates code snippets management?
2
1896
by: Wikicodia Admin | last post by:
Dears, Wikicodia is a wiki based project for sharing code snippets. We're collecting large number of code snippets for all code-based programming languages, scripts, shells and consoles. We wish you could help us. We're still BETA. Your suggestions, ideas and criticisms are very welcomed. We're waiting for you contributions. You can easily share and search our snippet using our Google Desktop Gadget. We're waiting for your JavaScript...
1
1579
by: StreamLogic | last post by:
All, I have posted this question in various groups, so I apologize for any overlap. I'd like to hear how other developers/architects keep track of old scripts, code snippets, relevant URLs, etc. I think most developers have an area where they keep reusable code they would like to use again. Year after year, we all develop things that can be reused in various projects.
2
1824
Frinavale
by: Frinavale | last post by:
I'm attempting to supplement the help for my code by providing other developers with code snippets that demonstrate how to use my classes/method. I've created a .snippet file and have placed it in the "<Visual Studio Folder>\Code Snippets\Visual Basic\My Snippets" folder. I've used the Code Snippets Manager and ensured that it included this folder so that I can access the snippets. Everything works well when I have 1 <CodeSnippet> tag...
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.