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 6774925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:50:45+00:00 2026-05-26T15:50:45+00:00

So I’ve got giant code base that needs to have a namespace added to

  • 0

So I’ve got giant code base that needs to have a namespace added to it. Instead of doing this manually, I thought of using grep, xargs & sed to add the namespace to all source files…

But my skills are not up to par.
Ideally

namespace foo 
{

Would be added after all the includes, and ‘}’ added after the #endif in the .h files.

For the .cpp files, adding ‘using namespace foo’ after all the includes would be sufficient.

I’ve been messing around with sed, but haven’t gotten very far.

Any help would be appreciated. Thanks!

  • 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-05-26T15:50:45+00:00Added an answer on May 26, 2026 at 3:50 pm

    This is not an easy task. Things that make it problematic include

    • Stuff that you do not want to place inside your new namespace such as
      • Constructs like language "C" { C-stuff }
      • Forward declarations of classes that are not yours. This gets n-times harder if you are using some external package that also doesn’t use namespaces.
    • Even finding where to place the namespace Foo { and the closing ‘}’ can be tough.
      • You do want to enclose forward declarations, except those that don’t belong to you.
      • You generally want to enclose anything at file scope that involves a pair of braces — except for things like language C.
      • Maintenance programmers (if your code has been around long enough) will have done all kinds of bad things to your code. They’ll put forward declarations inside classes or functions, between classes and functions, anywhere but the top that makes it is easy for a script.
      • You don’t want to double-nest things. It is suprisingly easy to do so.
      • For various reasons some people put what appears to be extraneous stuff at the end of a header. This can be a particularly nasty problem.
      • If you decide to try to enclose each class, struct, and enum you’re going to have to figure out where the start of the declaration really is. You want to wrap template declaration, if any, and of course doxygen comments and the like.
      • Finding the end of a class can be just nasty. People have this nasty tendency to put non-matching braces in comments and strings.

    Good luck! A script will take a bit more than a half an hour to write. It will take far less time than rewriting all your code. I suggest that you use something a tad more powerful than sed. Perl, python, and ruby are three good choices.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.