diff options
Diffstat (limited to 'source/Utility/RegularExpression.cpp')
-rw-r--r-- | source/Utility/RegularExpression.cpp | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/source/Utility/RegularExpression.cpp b/source/Utility/RegularExpression.cpp index 54f773365d992..0192e8b8a01a0 100644 --- a/source/Utility/RegularExpression.cpp +++ b/source/Utility/RegularExpression.cpp @@ -1,9 +1,8 @@ //===-- RegularExpression.cpp -----------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -13,10 +12,8 @@ #include <string> -//---------------------------------------------------------------------- // Enable enhanced mode if it is available. This allows for things like \d for // digit, \s for space, and many more, but it isn't available everywhere. -//---------------------------------------------------------------------- #if defined(REG_ENHANCED) #define DEFAULT_COMPILE_FLAGS (REG_ENHANCED | REG_EXTENDED) #else @@ -29,18 +26,15 @@ RegularExpression::RegularExpression() : m_re(), m_comp_err(1), m_preg() { memset(&m_preg, 0, sizeof(m_preg)); } -//---------------------------------------------------------------------- // Constructor that compiles "re" using "flags" and stores the resulting // compiled regular expression into this object. -//---------------------------------------------------------------------- RegularExpression::RegularExpression(llvm::StringRef str) - : m_re(), m_comp_err(1), m_preg() { - memset(&m_preg, 0, sizeof(m_preg)); + : RegularExpression() { Compile(str); } -RegularExpression::RegularExpression(const RegularExpression &rhs) { - memset(&m_preg, 0, sizeof(m_preg)); +RegularExpression::RegularExpression(const RegularExpression &rhs) + : RegularExpression() { Compile(rhs.GetText()); } @@ -51,15 +45,12 @@ operator=(const RegularExpression &rhs) { return *this; } -//---------------------------------------------------------------------- // Destructor // // Any previously compiled regular expression contained in this object will be // freed. -//---------------------------------------------------------------------- RegularExpression::~RegularExpression() { Free(); } -//---------------------------------------------------------------------- // Compile a regular expression using the supplied regular expression text and // flags. The compiled regular expression lives in this object so that it can // be readily used for regular expression matches. Execute() can be called @@ -69,7 +60,6 @@ RegularExpression::~RegularExpression() { Free(); } // RETURNS // True if the regular expression compiles successfully, false // otherwise. -//---------------------------------------------------------------------- bool RegularExpression::Compile(llvm::StringRef str) { Free(); @@ -80,13 +70,11 @@ bool RegularExpression::Compile(llvm::StringRef str) { return m_comp_err == 0; } -//---------------------------------------------------------------------- // Execute a regular expression match using the compiled regular expression // that is already in this object against the match string "s". If any parens // are used for regular expression matches "match_count" should indicate the // number of regmatch_t values that are present in "match_ptr". The regular // expression will be executed using the "execute_flags". -//--------------------------------------------------------------------- bool RegularExpression::Execute(llvm::StringRef str, Match *match) const { int err = 1; if (m_comp_err == 0) { @@ -155,19 +143,13 @@ bool RegularExpression::Match::GetMatchSpanningIndices( return false; } -//---------------------------------------------------------------------- // Returns true if the regular expression compiled and is ready for execution. -//---------------------------------------------------------------------- bool RegularExpression::IsValid() const { return m_comp_err == 0; } -//---------------------------------------------------------------------- // Returns the text that was used to compile the current regular expression. -//---------------------------------------------------------------------- llvm::StringRef RegularExpression::GetText() const { return m_re; } -//---------------------------------------------------------------------- // Free any contained compiled regular expressions. -//---------------------------------------------------------------------- void RegularExpression::Free() { if (m_comp_err == 0) { m_re.clear(); |