Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:31:27+00:00 2026-06-01T23:31:27+00:00

For example, my situation: I’m getting an input of 0, 1, true or false.

  • 0

For example, my situation:
I’m getting an input of “0”, “1”, “true” or “false”. (in any case)
what is preferred on terms of performance, code reading, any basically best-practice:

bool func(string param)
{
    string lowerCase = param;
    to_lower(lowerCase);
    if (lowerCase == "0" || lowerCase == "false")
    {
        return false;
    }
    if (lowerCase == "1" || lowerCase == "true")
    {
        return true;
    }
    throw ....
}

or:

bool func(string param)
{
    string lowerCase = param;
    to_lower(lowerCase);
    regex rxTrue  ("1|true");
    regex rxFalse ("0|false");

    if (regex_match(lowerCase, rxTrue)
    {
        return true;
    }
    if (regex_match(lowerCase, rxFalse)
    {
        return false;
    }
    throw ....
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:31:29+00:00Added an answer on June 1, 2026 at 11:31 pm

    The second is somewhat clearer, and easier to extend (e.g.: accepting
    "yes" and "no", or prefixes, with "1|t(?:rue)?)" and
    "0|f(?:alse)?". With regards to performance, the second can (and
    should) be made significantly faster by declaring the regex static
    (and const, while you’re at it), e.g.:

    static regex const rxTrue ( "1|true" , regex_constants::icase );
    static regex const rxFalse( "0|false", regex_constants::icase );
    

    Note too that by specifying case insensitivity, you’ll not have to
    convert the input to lower case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Will many import statements in a activity/apps affect performance in android. Example situation 1:
Can anyone please give me any example of situation in a database-driven application where
Noob question for Ruby on Rails- here's an example of my situation: If I
I will demonstrate the problem on a real example so the situation: there is
Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I
Example code: <html> <head> <script src=jquery-1.3.2.min.js type=text/javascript></script> <script src=jquery-ui-1.7.1.custom.min.js type=text/javascript></script> </head> <body> <table border=1
I'm not sure if this is possible. Here is an example situation: Something is
Can someone help me out with example of a situation in which absence of
developers! I can't understand next situation For Example I have model class Pg::City <
Imagine the following situation: example http://img4.imageshack.us/img4/9849/oop2.png As may notice the Handler -childs and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.