The present invention discloses the HTML escape character replacement method, which includes: determine whether the received parameter is a escape character; if the escape character is used to replace the escape character according to the parameter replaceEscapeChar, and return the replacement result; if it is not a escape character, the parameter is two; if the parameter is a two string, then A string replacement is made by calling replace according to the parameters, and the replacement results are returned. If the parameter is not two strings, then the replaceChar is called to replace the whole string according to the parameter, and the replacement result is returned. The method is simple, easy to use, common and extensible, and the development and maintenance of the method can be developed and the efficiency of development is improved. The quality, the high efficiency of replacement, the performance of the page data rendering is greatly improved compared with the previous way of processing. The invention also discloses a kind of HTML escape character replacement device and terminal, which has the beneficial effect.
【技术实现步骤摘要】
一种html转义字符替换方法、装置及终端
本专利技术涉及数据处理
,特别涉及一种html转义字符替换方法、装置及终端。
技术介绍
目前web前端string自带的replace方法或者开发人员基于stringprototype实现replaceAll方法都是一次只替换一种类型的字符串,当一次替换多种不同的非连续字符。如:后端数据通过jquery.html()方法渲染时,处于安全考虑需要替换内容中的html转义符(<>&等),如果沿用前面提到的方法来实现,特别是在一些列表数据展示时,此时的写法就会变成:xxx.replaceAll(“<”,”<;”).replaceAll(“>”,”>;”).replaceAll(“&”,”"&;”),即代码的复杂度随着替换的内容增加而增加,性能也随之变差。因此,如何高效地实现html转义字符替换,是本领域技术人员需要解决的技术问题。
技术实现思路
本专利技术的目的是提供一种html转义字符替换方法、装置及终端,实现简单、易用、通用,可扩展,方便开发和维护,提高了开发效率的质量,替换性能高效,较之前的处理方式,在页面数据渲染的性能上有很大的提升。为解决上述技术问题,本专利技术提供一种html转义字符替换方法,包括:判断接收到的参数是否为转义符;若是转义符,则根据所述参数调用replaceEscapeChar进行转义符替换,并返回替换结果;若不是转义符,则判断所述参数是否为两个;若所述参数是两个字符串时,则根据所述参数调用replace进行字符串替 ...
【技术保护点】
1.一种html转义字符替换方法,其特征在于,包括:判断接收到的参数是否为转义符;若是转义符,则根据所述参数调用replaceEscapeChar进行转义符替换,并返回替换结果;若不是转义符,则判断所述参数是否为两个;若所述参数是两个字符串时,则根据所述参数调用replace进行字符串替换,并返回替换结果;若所述参数不是两个字符串时,则根据所述参数调用replaceChar进行全部字符串的替换,并返回替换结果。
【技术特征摘要】
1.一种html转义字符替换方法,其特征在于,包括:判断接收到的参数是否为转义符;若是转义符,则根据所述参数调用replaceEscapeChar进行转义符替换,并返回替换结果;若不是转义符,则判断所述参数是否为两个;若所述参数是两个字符串时,则根据所述参数调用replace进行字符串替换,并返回替换结果;若所述参数不是两个字符串时,则根据所述参数调用replaceChar进行全部字符串的替换,并返回替换结果。2.根据权利要求1所述的html转义字符替换方法,其特征在于,判断接收到的参数是否为转义符,包括:利用replaceEscapeChar接口判断接收到的参数是否为转义符。3.根据权利要求2所述的html转义字符替换方法,其特征在于,判断所述数是否为两个,包括:利用replaceChar接口判断接收到的参数是否为两个。4.根据权利要求1-3任一项所述的html转义字符替换方法,其特征在于,当所述参数为超过为两个的字符串时,所述参数为json格式。5.一种html转义字符替换装置,其特征在于,包括:第一判断模块,用于判断接收到的参数是否为转义符;第一转换模块,用于当是转义符则根据所述参数调用replaceEscapeChar进行转义符替换,并返回替换结果;第二判断模块,用于当不是转义符则判断所述参数是否为两个;第二转换模块,用于当所述参数是...
【专利技术属性】
技术研发人员:陈高昌,
申请(专利权)人:广州华多网络科技有限公司,
类型:发明
国别省市:广东,44
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。