Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » String operation - trim function
String operation - trim function [message #60005] Fri, 01 August 2008 10:09 Go to next message
Eclipse UserFriend
Originally posted by: taus.proceedinnovation.com

Hi,
I am trying to write Audits in a EMF/GMF context and looking for a
function to trim leading blanks from a String. Is there such a function
available?
I tried to work with def: but could not get it to run in my environment.
Even the most simple version "def: trim(s:String): String = s" did
produce an error saying Invalid OCL. Can you pls tell me what I am doing
wrong here.

Walter
Re: String operation - trim function [message #60052 is a reply to message #60005] Fri, 01 August 2008 12:16 Go to previous messageGo to next message
Patry Olivier is currently offline Patry OlivierFriend
Messages: 54
Registered: July 2009
Member
Walter Taus a écrit :
> Hi,
> I am trying to write Audits in a EMF/GMF context and looking for a
> function to trim leading blanks from a String. Is there such a function
> available?
> I tried to work with def: but could not get it to run in my environment.
> Even the most simple version "def: trim(s:String): String = s" did
> produce an error saying Invalid OCL. Can you pls tell me what I am doing
> wrong here.
>
> Walter
Hi,

trim() already exists in OCL

If you want to use a helper, you might define the context, String

helper context String def : myTrim : String = self.doSomething;

Or something like that.
Re: String operation - trim function [message #60076 is a reply to message #60005] Fri, 01 August 2008 13:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Walter,

The OCL Standard Library does not define a String operation that does a
trim.

I don't think that you can define operations in-line in a GMF Audit
specification.

I don't know how GMF allows you to extend the OCL environment; best to
ask on the GMF newsgroup about that. However, if you can specify
additional operations using OCL, then something like this may work:

context String
def: at(i : Integer) : String =
self.substring(i, i)
def: trimmed : String =
let whitespace : Set(String) = Set{' ', '\t', '\n'},
range : Sequence(Integer) = Sequence{1..self.size()},
rrange : Sequence(Integer) = range->sortBy(e| -e),
start : Integer = range->any(i|whitespace->excludes(self.at(i))),
end : Integer = rrange->any(i|whitespace->excludes(self.at(i))) in
if start <> null then
if end <> null then
self.substring(start, end)
else
self.substring(start, self.size())
endif
else
if end <> null then
self.substring(1, end)
else
self
endif
endif

Otherwise, you could follow the example of using Java to define a
regular-expression-matching operation on the String type in the OCL
Developer Guide. Look for it under the "Advanced" heading in the
Programmer's Guide, in a "Customizing the Environment" topic.

HTH,

Christian


Walter Taus wrote:
> Hi,
> I am trying to write Audits in a EMF/GMF context and looking for a
> function to trim leading blanks from a String. Is there such a function
> available?
> I tried to work with def: but could not get it to run in my environment.
> Even the most simple version "def: trim(s:String): String = s" did
> produce an error saying Invalid OCL. Can you pls tell me what I am doing
> wrong here.
>
> Walter
Re: String operation - trim function [message #60148 is a reply to message #60052] Mon, 04 August 2008 08:26 Go to previous message
Patry Olivier is currently offline Patry OlivierFriend
Messages: 54
Registered: July 2009
Member
Olivier PATRY a écrit :
> Walter Taus a écrit :
>> Hi,
>> I am trying to write Audits in a EMF/GMF context and looking for a
>> function to trim leading blanks from a String. Is there such a
>> function available?
>> I tried to work with def: but could not get it to run in my
>> environment. Even the most simple version "def: trim(s:String): String
>> = s" did produce an error saying Invalid OCL. Can you pls tell me what
>> I am doing wrong here.
>>
>> Walter
> Hi,
>
> trim() already exists in OCL
>
> If you want to use a helper, you might define the context, String
>
> helper context String def : myTrim : String = self.doSomething;
>
> Or something like that.
Oh, sorry I reply thinking about ATL implementation of OCL. Forget about
pure OCL.
Previous Topic:Carriage return in OCL expressions
Next Topic:Define custom operations on primitive types
Goto Forum:
  


Current Time: Sat Apr 20 03:36:43 GMT 2024

Powered by FUDForum. Page generated in 0.03095 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top