I'm too dense to figure this one out today: The
second (and probably third) assertions fail...
require 'test/unit'
class String
def to_tex
gsub( /(?!\w)'(.*?)'/, '`\1\'' )
end
end
class StringTC < Test::Unit::TestCase
def test_single_quotation
assert_equal( "`single quotation'", "'single quotation'".to_tex )
assert_equal( "isn't fool'd", "isn't fool'd".to_tex )
assert_equal( "2' x 4'", "2' x 4'".to_tex )
end
end
Any help would be appreciated and probably evoke "duh!"
Thanks,
···
--
Bil Kleb, Hampton, Vriginia
http://fun3d.larc.nasa.gov
ts1
(ts)
2
gsub( /(?!\w)'(.*?)'/, '`\1\'' )
(?!) is a zero-width negative look-ahead
assert_equal( "isn't fool'd", "isn't fool'd".to_tex )
When the regexp engine is at this position (just before ')
"isn't fool'd"
^
>
* it look if it don't have a word character (\w) : this is true because the
first next character is '
* then it look if it has ' : it's true and it match
Guy Decoux
Robert
(Robert)
3
"ts" <decoux@moulon.inra.fr> schrieb im Newsbeitrag
news:200501271020.j0RAKGL04736@moulon.inra.fr...
> gsub( /(?!\w)'(.*?)'/, '`\1\'' )
(?!) is a zero-width negative look-ahead
> assert_equal( "isn't fool'd", "isn't fool'd".to_tex )
When the regexp engine is at this position (just before ')
"isn't fool'd"
^
>
* it look if it don't have a word character (\w) : this is true because
the
first next character is '
* then it look if it has ' : it's true and it match
These seem to work:
class String
def to_tex
gsub( /(?:\A|(?![\w']))'(.*?)'/, '`\\1\'' )
end
end
=> nil
"'single quotation'".to_tex
=> "`single quotation'"
class String
def to_tex
gsub( /'((?:[^\\']|\\.)*)'/, '`\\1\'' )
end
end
=> nil
"'single quotation'".to_tex
=> "`single quotation'"
But I dunno whether they fix all of your problems.
Kind regards
robert
ts1
(ts)
4
But I dunno whether they fix all of your problems.
You want Onigurama, with a zero-width negative look-behind (?<!)
Guy Decoux