escaping

ASCII to HTML-Entities Escaping in Java

梦想的初衷 提交于 2019-12-04 14:21:34
I found this website with escape codes and I'm just wondering if someone has done this already so I don't have to spend couple of hours building this logic: StringBuffer sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s.charAt(i); switch (c) { case '\u25CF': sb.append("●"); break; case '\u25BA': sb.append("►"); break; /* ... the rest of the hex chars literals to HTML entities */ default: sb.append(c); break; } } These "codes" is a mere decimal representation of the unicode value of the actual character. It seems to me that something like this would work,

Using YQL multi-query & XPath to parse HTML, how to escape nested quotes?

跟風遠走 提交于 2019-12-04 13:21:50
问题 The title is more complicated than it has to be, here's the problem query. SELECT * FROM query.multi WHERE queries=" SELECT * FROM html WHERE url='http://www.stumbleupon.com/url/http://www.guildwars2.com' AND xpath='//li[@class=\"listLi\"]/div[@class=\"views\"]/a/span'; SELECT * FROM xml WHERE url='http://services.digg.com/1.0/endpoint?method=story.getAll&link=http://www.guildwars2.com'; SELECT * FROM json WHERE url='http://api.tweetmeme.com/url_info.json?url=http://www.guildwars2.com';

Single quoted string vs. double quoted string

社会主义新天地 提交于 2019-12-04 12:05:42
Why do we need an escape character for single quoted string, but not for a double quoted string? a = 'hello how\'s it going' a1 = 'hello how's it going' b = "hello how's it going" assert(a==b) # Passes assert(a1==b) # Errors The error message: File "string.py", line 1 a = 'hello how's it going' ^ SyntaxError: invalid syntax It doesn't matter if you use ' or " around the string to mark it as string literal. But you can't use that character inside the string literal without escaping it using a \ in front of it - otherwise Python interprets it as the end of the string. For example " inside a "

Twig with Symfony 2 displaying json encoded variables different between prod and dev

泄露秘密 提交于 2019-12-04 11:51:58
问题 We're building a Symfony 2 application that sends some data from controller to view: Controller $user = array( 'configuration' => array( 'levels' => array( 'warning' => 0.05, 'danger' => 0.10, ), ), ); return $this->render( 'MyWebsiteBundle:Core:searchResults.html.twig', array( 'userJSON' => json_encode($user) ) ); View <script language="javascript"> user = $.parseJSON("{{ userJSON }}"); </script> Result On dev the result looks like this and works as expected: user = $.parseJSON("\x7B

jinja2: html escape variables

℡╲_俬逩灬. 提交于 2019-12-04 10:00:31
问题 how do I html-escape dangerous unsanitized input in jinja2? Can I do it inside the template or must it be done in python code? I have a variable that may contain da<ngero>u&s chars. How do I escape it in jinja2 回答1: e.g. {{ user.username|e }} Pipe it through the |e filter Jinja: Template Designer Documentation -> HTML Escaping 回答2: You could also tell the environment to autoescape everything: e = Environment(loader=fileloader, autoescape=True) note: in jinja1 this is auto_escape 回答3: If you

LibXML2 Sax Parsing and ampersand

爱⌒轻易说出口 提交于 2019-12-04 09:37:52
问题 I've encountered (what I think is) a strange behavior when using the sax parser, and I wanted to know if it's normal. I'm sending this XML through the SAX parser: <site url="http://example.com/?a=b&b=c"; /> The "&" gets converted to " &" when the startElement callback is called. Is it supposed to do that? If so, I would like to understand why. I've pasted an example demonstrating the issue here: #include <stdlib.h> #include <libxml/parser.h> static void start_element(void * ctx, const xmlChar

What is the C++ equivalent of the C# @ symbol prefixing strings?

↘锁芯ラ 提交于 2019-12-04 09:06:46
问题 What is the C++ equivalent of the C# @ symbol prefixing strings? For escaping symbols automatically? Example: var howManySlashesAreThereIn = @"\\\\\\" ; 回答1: In C++11, you can use raw string literals: std::string s = R"(This\is\a\raw\string\literal)"; std::string s = R"*(This \one contains \a )", which would normally end the string)*"; Here's the C++11 FAQ word on it, and a reference. 回答2: You're looking for the "raw string" feature of C++ but it's a fairly recent addition (C++11, I believe).

Regex expression to match whole word with special characters not working ? [duplicate]

二次信任 提交于 2019-12-04 07:57:26
This question already has an answer here: Regex expression to match whole word ? 1 answer I was going through this question C#, Regex.Match whole words It says for match whole word use "\bpattern\b" This works fine for match whole word without any special characters since it is meant for word characters only! I need an expression to match words with special characters also. My code is as follows class Program { static void Main(string[] args) { string str = Regex.Escape("Hi temp% dkfsfdf hi"); string pattern = Regex.Escape("temp%"); var matches = Regex.Matches(str, "\\b" + pattern + "\\b" ,

Why does PyCharm use double backslash to indicate escaping?

馋奶兔 提交于 2019-12-04 07:54:07
For instance, I write a normal string and another "abnormal" string like this: Now I debug it, finding that in the debug tool, the "abnormal" string will be shown like this: Here's the question: Why does PyCharm show double backslashes instead of a single backslash? As is known to all, \' means ' . Is there any trick? What I believe is happening is the ' in your c variable string needs to be escaped and PyCharm knows this at runtime, given you have surrounded the full string in " (You'll notice in the debugger, your c string is now surrounded by ' ). To escape the single quote it changes it to

Qt and unicode escape string

眉间皱痕 提交于 2019-12-04 07:29:38
I'm getting from server data using signal and slot. Here is slot part: QString text(this->reply->readAll()); Problem is, that in text variable will be unicode escape, for example: \u043d\u0435 \u043f\u0430\u0440\u044c\u0441\u044f ;-) Is there any way to convert this? Adam W Did you try: QString text = QString::fromUtf8(this->reply->readAll()); http://doc.qt.io/qt-5/qstring.html#fromUtf8 Assuming it's Utf8, otherwise use fromUtf16 I think this is what you needed: (Find occurrences of \uCCCC using regex and replace them by the QChar with unicode number CCCC in base 16) QRegExp rx("(\\\\u[0-9a-fA