escaping

Convert characters in a c string to their escape sequences

南楼画角 提交于 2019-12-04 07:28:10
I need a function like string ToLiteral(string input) from this post . Such that char *literal = to_literal("asdf\r\n"); Would yield literal ==> "asdf\\r\\n" . I've googled around, but not been able to find anything (guess that I've must be using the wrong terms). However, I assume that a library with this functionality must be out there somewhere... Thank you for the interresting answers. Googling "c string escape function" by the way seems to be the key to obtaining even more examples and GLIB provides g_strescape () which seems to be exactly what I need. There's no built-in function for

Why does io:format support ~n when \\n does the same thing?

放肆的年华 提交于 2019-12-04 06:55:33
These two give identical output: 1> io:format("Hello, world!~n"). Hello, world! ok 2> io:format("Hello, world!\n"). Hello, world! ok Why does io:format support ~n when \n does the same thing? Are there any differences? According to "Programming Erlang", ~n outputs the platform-specific new line sequence ( \n on Unix, \r\n on Windows, etc.). I think \n just writes the \n character, but am not sure. According to io document , The general format of a control sequence is ~F.P.PadModC . So the format must begin with ~ , and character n is one of the control sequences with the definition Writes a

feof() and fscanf() stop working after scanning byte 1b as a char. Is it because it is 'ESC' in ascii? What can I do?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 06:38:25
问题 I'm currently writing a program that processes PPM files (P6 type, not P3) The problem is that some images have the byte 0x1b which, according to the ascii table is known as 'ESC' The following is pretty much my code: // all the includes there, , , ... int main(void) { FILE *finput; int number[7]; char r, g, b; finput = fopen("my.ppm", "r"); /* The code where I read the P6 numRows numColumns 255\n ...Lets assume that part works well */ while(!feof(finput)) { num[0] = fscanf(finput, "%c", &r);

Is it okay to use HTML entities in attributes?

不打扰是莪最后的温柔 提交于 2019-12-04 06:33:08
I have been using slim, and suddenly noticed that it escapes everything by default. So the anchor tag looks something like this: <a href="/users/lyann/followers"> <img class="user-image" src="http://adasdasdasd.cloudfront.net/users&# 47;2011/05/24/4asdasd/asdasd.jpg" /> Is it okay for the href and src attributes to be escaped like this? Are there any other implications? All browsers seems to render it without a problem, though. Yes, it's perfectly fine. Character references are valid inside attributes, too, and will be treated as character references just the same. For reference, see: A

OpenCsv reading file with escaped separator

徘徊边缘 提交于 2019-12-04 06:29:56
问题 Am using opencsv 2.3 and it does not appear to be dealing with escape characters as I expect. I need to be able to handle an escaped separator in a CSV file that does not use quoting characters. Sample test code: CSVReader reader = new CSVReader(new FileReader("D:/Temp/test.csv"), ',', '"', '\\'); String[] nextLine; while ((nextLine = reader.readNext()) != null) { for (String string : nextLine) { System.out.println("Field [" + string + "]."); } } and the csv file: first field,second\,field

RegEx: Don't match a certain character if it's inside quotes

こ雲淡風輕ζ 提交于 2019-12-04 05:55:40
Disclosure: I have read this answer many times here on SO and I know better than to use regex to parse HTML. This question is just to broaden my knowledge with regex. Say I have this string: some text <tag link="fo>o"> other text I want to match the whole tag but if I use <[^>]+> it only matches <tag link="fo> . How can I make sure that > inside of quotes can be ignored. I can trivially write a parser with a while loop to do this, but I want to know how to do it with regex. Vasili Syrakis Regular Expression: <[^>]*?(?:(?:('|")[^'"]*?\1)[^>]*?)*> Online demo: http://regex101.com/r/yX5xS8 Full

how can I enter character “<” in strings.xml?

孤者浪人 提交于 2019-12-04 05:37:43
问题 I want to enter string " -< " in strings.xml file in eclipse, the string has character < and I couldn't add it to xml file without error! I even tried to escaping by \ character: <string name="search_target_arrow"> -\< </string> or enclosing it between "" as below: <string name="search_target_arrow">" -< "</string> but none worked. Then finally with help of kind users here I found that this would be the correct way to enter such chars in xml: <string name="search_target_arrow"> -&lt; </string

MySQL LIKE operator with wildcard and backslash

淺唱寂寞╮ 提交于 2019-12-04 05:36:11
It's frustrated with MySQL's pattern escaping used in LIKE operator. root@dev> create table foo(name varchar(255)); Query OK, 0 rows affected (0.02 sec) root@dev> insert into foo values('with\\slash'); Query OK, 1 row affected (0.00 sec) root@dev> insert into foo values('\\slash'); Query OK, 1 row affected (0.00 sec) root@dev> select * from foo where name like '%\\\\%'; Empty set (0.01 sec) root@dev> select * from foo; +------------+ | name | +------------+ | with\slash | | \slash | +------------+ 2 rows in set (0.00 sec) root@dev> select * from foo where name like '%\\\\%'; Empty set (0.00

Json.Parse escape newline characters

≡放荡痞女 提交于 2019-12-04 05:32:46
I have a page where I am trying to parse following json string using JSON.parse '[{"Name":"Eggs","Complete":false,"Notes":"Notes here\n"},{"Name":"Sugar","Complete":false,"Notes":null}]' But following code gives error "Uncaught SyntaxError: Unexpected token" var groceriesJson = JSON.parse(jsonString); Then I came to know that its because of \n in json string. So I did try this solution . But no luck. Still same error "Uncaught SyntaxError: Unexpected token" function escapeSpecialChars(jsonString) { return jsonString.replace(/\\n/g, "\\n") .replace(/\\'/g, "\\'") .replace(/\\"/g, '\\"')

What does it mean to call an escaping closure after the function returns? [duplicate]

会有一股神秘感。 提交于 2019-12-04 05:23:31
问题 This question already has answers here : Escaping Closures in Swift (5 answers) Closed 2 years ago . I was reading the apple developer documentation's definition of escaping closures. It says "a closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns" I am not sure what the last part is supposed to mean, what does it mean by "after the function returns"? Does it mean "after the function returns a value"? 回答1: