Commit 94f56c1c authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed charstring pattern subtyping for empty strings (bug 568340)


Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
Change-Id: I8dcf52db6b24dc91f302452cc1c3c89bd73a5176
parent 5d8f2d38
......@@ -620,6 +620,16 @@ namespace Common {
string* regexp(const string& instr, const string& expression,
const Int& groupno, bool nocase)
{
string* retval = regexp_internal(instr, expression, groupno, nocase);
if (retval != NULL) {
return retval;
}
return new string();
}
string* regexp_internal(const string& instr, const string& expression,
const Int& groupno, bool nocase)
{
string *retval=0;
......@@ -664,13 +674,11 @@ namespace Common {
if(pmatch[nmatch].rm_so != -1 && pmatch[nmatch].rm_eo != -1)
retval = new string(instr.substr(pmatch[nmatch].rm_so,
pmatch[nmatch].rm_eo - pmatch[nmatch].rm_so));
else retval=new string();
}
Free(pmatch);
if(ret_val!=0) {
if(ret_val==REG_NOMATCH) {
regfree(&posix_regexp);
retval=new string();
}
else {
/* regexp error */
......
......@@ -61,8 +61,13 @@ namespace Common {
extern Real int2float(const int_val_t& value);
extern int_val_t* float2int(const Real& value, const Location& loc);
extern string* float2str(const Real& value);
// returns a pointer to an empty string if the input doesn't match the expression (as in TTCN-3)
extern string* regexp(const string& instr, const string& expression,
const Int& groupno, bool nocase);
// returns a null pointer if the input doesn't match the expression
// (to distinguish between a matching empty string and non-matching)
extern string* regexp_internal(const string& instr, const string& expression,
const Int& groupno, bool nocase);
extern ustring* regexp(const ustring& instr, const ustring& expression,
const Int& groupno, bool nocase);
extern string* remove_bom(const string& encoded_value);
......
......@@ -508,8 +508,8 @@ tribool StringPatternConstraint::match(const string& str) const
{
string patt = pattern->get_full_str();
if (patt.size()==0) return TRIBOOL(str.size()==0);
string *result = regexp(str, string('(')+patt+string(')'), 0, pattern->get_nocase());
bool rv = (result->size()!=0);
string *result = regexp_internal(str, string('(')+patt+string(')'), 0, pattern->get_nocase());
bool rv = (result!=0);
delete result;
return TRIBOOL(rv);
}
......
Bug568340
Bug568340.exe
Bug568340*.cc
Bug568340*.hh
/******************************************************************************
* Copyright (c) 2000-2020 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Baranyi, Botond
*
******************************************************************************/
// pattern subtyping for empty strings (bug 568340)
module Bug568340 {
type charstring T (pattern "(/?+)#(0,1)");
const T val := "";
}
##############################################################################
# Copyright (c) 2000-2020 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
#
# Contributors:
# Botond, Baranyi
#
##############################################################################
TOPDIR := ../..
include $(TOPDIR)/Makefile.regression
.PHONY: all clean dep
TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
TTCN3_MODULES = Bug568340.ttcn
GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc)
GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
ifdef CODE_SPLIT
GENERATED_SOURCES := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), .cc _seq.cc _set.cc _seqof.cc _setof.cc _union.cc))
else ifdef SPLIT_TO_SLICES
POSTFIXES := $(foreach file, $(SPLIT_TO_SLICES), $(addsuffix $(file), _part_))
POSTFIXES := $(foreach file, $(POSTFIXES), $(addprefix $(file), .cc))
GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), $(POSTFIXES)))
GENERATED_SOURCES += $(GENERATED_SOURCES2)
endif
OBJECTS = $(GENERATED_SOURCES:.cc=.o)
TARGET = Bug568340$(EXESUFFIX)
all: $(TARGET)
$(TARGET): $(GENERATED_SOURCES) $(USER_SOURCES)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ -L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) \
-L$(OPENSSL_DIR)/lib -lcrypto $($(PLATFORM)_LIBS)
$(GENERATED_SOURCES) $(GENERATED_HEADERS): $(TTCN3_MODULES)
$(TTCN3_COMPILER) $(COMPILER_FLAGS) $^
clean distclean:
$(RM) $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
$(GENERATED_SOURCES) compile *.log
dep: $(GENERATED_SOURCES)
makedepend $(CPPFLAGS) $(GENERATED_SOURCES)
......@@ -31,7 +31,7 @@ CODIRS := dynamicTemplate styleGuide topLevelPdu \
asn1_hyphen nameClash portTranslation UntaggedOnTopLevelUnionSwitch \
typeDescrGenWIthNoXER languageSpec asn1_opentype openTypeXER \
asnStringSubtypes componentParameter realtimeKeywords Bug550526 \
Bug550623 Bug552232
Bug550623 Bug552232 Bug568340
ifdef DYN
CODIRS += mfgen-xsd
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment