in reply to regex subst not DWIM

With a program this size with a vague dataset it would be helpful to have an input file with an example of what output you want to get, then we could actually run it. Just a minimal dataset will do.

                - Ant
                - Some of my best work - (1 2 3)

Replies are listed 'Best First'.
Re^2: regex subst not DWIM
by girarde (Hermit) on Dec 19, 2007 at 22:22 UTC
    Here you go:
    public virtual void Destroy(object O) { try { m_container.Mockery.VerifyAllExpectationsHaveBeenMet() +; } finally { m_container = null; } }
      Ok... first problem I see (besides the params regexp already pointed out... is your not_method regexp piece...

      you didn't put it in a container, so your pipes aren't doing what you expect...

      if ($line =~ /^\W*(?:$not_method)/) {
      That'll work better.

      Update a \b at the end would also help make sure you don't match a string starting with as or if etc...

      if ($line =~ /^\W*(?:$not_method)\b/) {

                      - Ant
                      - Some of my best work - (1 2 3)

      And what should it look like once converted? When I run it I see it getting the copyright and nothing else changes.

                      - Ant
                      - Some of my best work - (1 2 3)

        It should look like:
        /// <summary> /// public virtual void Destroy(object O) /// </summary> /// <param name = "O">object</param> public virtual void Destroy(object O) { try { m_container.Mockery.VerifyAllExpectationsHaveBeenMet() +; } finally { m_container = null; } }
        Also, if the method dataset has no arguments, running it inserts a header (just the lines for summary) and appends another empty pair of parens to the declaration line. In other words, this as the dataset:
        public virtual void Destroy() { try { m_container.Mockery.VerifyAllExpectationsHaveBeenMet() +; } finally { m_container = null; } }
        results in this in the output:
        /// <summary> /// public virtual void Destroy() /// </summary> public virtual void Destroy()() { try { m_container.Mockery.VerifyAllExpectationsHaveBeenMet() +; } finally { m_container = null; } }