Wrap string in brackets

@param string|VerbalExpression $text       Text to wrap
@param boolean                 $subPattern Use sub pattern capturing

@return string
966593
private function addBrackets($text, $subPattern = null)
    {
        if ($text instanceof VerbalExpression) {
            return $text->compile();
        }

        return $this->generateOpeningBracket($subPattern) .  $text . ')';
    }
641108
def chain_sub_regexes(phrase, *regex_sub_pairs):
    '''
    
    '''
    for regex, substitution in regex_sub_pairs:
        if isinstance(regex, basestring):
            regex = re.compile(regex)
        phrase = regex.sub(substitution, phrase)
    return phrase
393865
protected function renderText($text)
	{
		if ($this->enableNewlines) {
			return preg_replace("/(  \n|\n)/", "\\\\\\\\\n", $this->escapeLatex($text[1]));
		} else {
			return parent::renderText($text);
		}
	}
891586
public String formatAsString(final String formatPattern, final String value, final Locale locale) {
        return format(formatPattern, value, locale).getText();
    }
1195148
public static function unwrap(string $text, string $wrappers) : string
    {
        $size = strlen($wrappers);
        for ($i = 0; $i < $size; $i += 2) {
            if (substr($text, 0, 1) == substr($wrappers, $i, 1)
               && substr($text, -1) == substr($wrappers, $i + 1, 1))
                return substr($text, 1, strlen($text) - 2);
        }
        return $text;
    }
807218
public function flushUrl($subPattern) {
        $result = array();
        foreach (Mage::helper('turpentine/varnish')->getSockets() as $socket) {
            $socketName = $socket->getConnectionString();
            try {
                // We don't use "ban_url" here, because we want to do lurker friendly bans.
                // Lurker friendly bans get cleaned up, so they don't slow down Varnish.
                $socket->ban('obj.http.X-Varnish-URL', '~', $subPattern);
            } catch (Mage_Core_Exception $e) {
                $result[$socketName] = $e->getMessage();
                continue;
            }
            $result[$socketName] = true;
        }
        return $result;
    }
22149
def paragraph_sub(match):
    """"""
    text = re.sub(r'  \n', r'\n<br/>\n', match.group(0).strip())
    return '<p>{}</p>'.format(text)
452956
private boolean matchNoAsterisk(String toMatch, String subpattern) {

		if (logger.isLoggable(Level.FINEST)) {
			logger.finest("Entering matchNoAsterisk with  toMatch = " + toMatch + " and subpattern = " + subpattern);
		}			

		int toMatchLen = toMatch.length();
		int subpatternLen = subpattern.length();

		if (toMatchLen != subpatternLen) {
			if (logger.isLoggable(Level.FINEST)) {
				logger.finest("FAIL: in matchNoAsterisk:  toMatchLen = " + toMatchLen + " != subpatternLen = " + subpatternLen);
			}			
			return false;
		}

		for (int i = 0; i < toMatchLen; i++) {
			if (subpattern.substring(i,i+1).equals("*")) {
				logger.fine("FAIL: in matchNoAsterisk: Shouldn't have encountered a '*' in matchNoAsterisk, toMatch = " + toMatch + ", subPattern = " + subpattern);
				throw new IllegalStateException("Shouldn't have encountered a '*' in matchNoAsterisk, toMatch = " + toMatch + ", subPattern = " + subpattern);
			} else if (subpattern.substring(i,i+1).equals("?")) {
				// Nothing needed) 
			} else {
				if (subpattern.charAt(i) != toMatch.charAt(i)) {
					if (logger.isLoggable(Level.FINEST)) {
						logger.finest("FAIL: in matchNoAsterisk: mismatch at index: " + i + ". The char subpattern.charAt(i)= "  + subpattern.charAt(i) + " != toMatch.charAt(i) = " + toMatch.charAt(i));
					}			
					return false;
				}			
				// else continue
			}
		}

		if (logger.isLoggable(Level.FINEST)) {
			logger.finest("SUCCESS: in matchNoAsterisk");
		}			

		return true;
	}
1070141
function smart_wordwrap($string, $width = 75, $break = "\n")
    {
        // split on problem words over the line length
        $pattern = sprintf('/([^ ]{%d,})/', $width);
        $output  = '';
        $words   = preg_split($pattern, $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

        foreach ($words as $word) {
            if (false !== strpos($word, ' ')) {
                // normal behaviour, rebuild the string
                $output .= $word;
            } else {
                // work out how many characters would be on the current line
                $wrapped = explode($break, wordwrap($output, $width, $break));
                $count   = $width - (strlen(end($wrapped)) % $width);

                // fill the current line and add a break
                $output .= substr($word, 0, $count) . $break;

                // wrap any remaining characters from the problem word
                $output .= wordwrap(substr($word, $count), $width, $break, true);
            }
        }

        // wrap the final output
        return wordwrap($output, $width, $break);
    }
829123
public function anythingBut($value, $subPattern = null)
    {
        return $this->add('[^' . $this->sanitise($value) . ']*', $subPattern);
    }
1267613
public static function subDescription(string $text, int $length): string
    {
        return mb_strlen($text, 'utf-8') > $length ? substr($text, 0, $length - 3) . '...' : $text;
    }
515011
protected function processInline($text)
    {
        while ($text) {
            if (preg_match(self::MATCH_LINK, $text, $m)) {
                return $this->processLink($m[1], $m[2], $m[3], $m[4]);
            }

            $importantTextAhead = $this->lookAhead($text, self::STRONG_START_END);
            $emphasizedTextAhead = $this->lookAhead($text, self::EMPHASIZED_START_END);

            if ($importantTextAhead === false) {
                $importantTextAhead = $this->lookAhead($text, self::STRONG_START_END_TYPE_2);
            }

            if ($emphasizedTextAhead === false) {
                $emphasizedTextAhead = $this->lookAhead($text, self::EMPHASIZED_START_END_TYPE_2);
            }

            if ($importantTextAhead !== false && $emphasizedTextAhead !== false) {
                if ($importantTextAhead <= $emphasizedTextAhead) {
                    $unformattedText = mb_substr($text, 0, $importantTextAhead);
                    $importantText = mb_substr($text, $importantTextAhead);
                    $this->text($unformattedText);

                    return $this->processStrong($importantText);
                } else {
                    $unformattedText = mb_substr($text, 0, $emphasizedTextAhead);
                    $emphasizedText = mb_substr($text, $emphasizedTextAhead);
                    $this->text($unformattedText);

                    return $this->processEmphasized($emphasizedText);
                }
            } elseif ($importantTextAhead !== false) {
                $unformattedText = mb_substr($text, 0, $importantTextAhead);
                $importantText = mb_substr($text, $importantTextAhead);
                $this->text($unformattedText);

                return $this->processStrong($importantText);
            } elseif ($emphasizedTextAhead !== false) {
                $unformattedText = mb_substr($text, 0, $emphasizedTextAhead);
                $emphasizedText = mb_substr($text, $emphasizedTextAhead);
                $this->text($unformattedText);

                return $this->processEmphasized($emphasizedText);
            }

            $text = $this->processRestOfLine($text);
        };

        return ''; //All text is consumed
    }
1257583
public static function wrap($text, $left_margin = 0, $right_margin = 0,
        $width = null)
    {
        if (empty($width)) {
            $width = self::getWidth();
        }
        $width = $width - abs($left_margin) - abs($right_margin);
        $margin = str_repeat(' ', $left_margin);
        return $margin . wordwrap($text, $width, PHP_EOL . $margin);
    }
163518
String getPattern() {
        final StringBuilder result = new StringBuilder();

        if (myPrefix != null) {
            result.append(myPrefix);
        }
        if (mySuffixes != null) {
            result.append("*");
            for (final Literal sub : mySuffixes) {
                result.append(sub);
                result.append("*");
            }
        }
        if (myPostfix != null) {
            result.append(myPostfix);
        }
        return result.toString();
    }
1119021
public function setText($text) {
		if( !is_string($text) ) {
			throw new \Exception('RequireStringParameter');
		}
		$this->setTEXTBody(strip_tags($text));
		$this->setHTMLBody(nl2br($text));
	}
449780
public static Predicate<MailMessage> forSubject(final Pattern subjectPattern) {
		return new Predicate<MailMessage>() {
			@Override
			public boolean apply(final MailMessage input) {
				return subjectPattern.matcher(input.getSubject()).matches();
			}

			@Override
			public String toString() {
				return String.format("subject to match pattern '%s'", subjectPattern);
			}
		};
	}
1119194
function PRVTadjustWrapText( $text, $actual, $width, &$x, &$adjust, $justification )
    {
        switch ( $justification )
        {
        case 'left':
            return;
            break;
        case 'right':
            $x += $width - $actual;
            break;
        case 'center':
        case 'centre':
            $x += ($width - $actual) / 2;
            break;
        case 'full':
            // count the number of words
            $words = explode( ' ', $text );
            $nspaces = count($words) - 1;
            if ( $nspaces > 0 )
            {
                $adjust = ($width-$actual) / $nspaces;
            }
            else
            {
                $adjust = 0;
            }
        break;
    }
    }