我有一个scala(2.10.4)应用程序,其中电子邮件地址传递很多,我想实现一个在IO调用的抽象来"清理"已经验证的电子邮件地址.
使用scala.Proxy几乎是我想要的,但我遇到了不对称平等的问题.
class SanitizedEmailAddress(s: String) extends Proxy with Ordered[SanitizedEmailAddress] {
val self: String = s.toLowerCase.trim
def compare(that: SanitizedEmailAddress) = self compareTo that.self
}
object SanitizedEmailAddress {
def apply(s: String) = new SanitizedEmailAddress(s)
implicit def sanitize(s: String): SanitizedEmailAddress = new SanitizedEmailAddress(s)
implicit def underlying(e: SanitizedEmailAddress): String = e.self
}
Run Code Online (Sandbox Code Playgroud)
我想要
val sanitizedEmail = SanitizedEmailAddress("Blah@Blah.com")
val expected = "blah@blah.com"
assert(sanitizedEmail == expected) // => true
assert(expected == sanitizedEmail) // => true, but this currently returns false :(
Run Code Online (Sandbox Code Playgroud)
或者具有类似功能的东西.有没有非繁琐的方法吗?
assert(sanitizedEmail.self == …Run Code Online (Sandbox Code Playgroud) 我希望能够突出显示(即用颜色或其他方式包裹)所有与CKEditor中的正则表达式匹配的文本.我可能会添加一个按钮来执行此操作,还可以使用一个按钮来删除突出显示.我的具体用例是突出显示我的HTML模板中的所有胡子变量(让我们很容易看到有胡子变量的位置).
我已经实现了一个版本,我用一个span替换正则表达式匹配的mustaches,然后是捕获组.当我测试时,这似乎在某些模板上中断.
要删除突出显示,我使用editor.removeStyle,它似乎并不适用于所有情况.
以下是我实施的示例:
editor.addCommand( 'highlightMustache', {
exec: function( editor ) {
editor.focus();
editor.document.$.execCommand( 'SelectAll', false, null );
var mustacheRegex = /{{\s?([^}]*)\s?}}/g;
var data = editor.getData().replace(mustacheRegex, '<span style="background-color: #FFFF00">{{ $1 }}</span>');
editor.setData( data );
}
});
// command to unhighlight mustache parameters
editor.addCommand( 'unhighlightMustache', {
exec: function( editor ) {
editor.focus();
editor.document.$.execCommand( 'SelectAll', false, null );
var style = new CKEDITOR.style( { element:'span', styles: { 'background-color': '#FFFF00' },type:CKEDITOR.STYLE_INLINE,alwaysRemoveElement:1 } );
editor.removeStyle( style );
editor.getSelection().removeAllRanges();
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢!