string-literals

Searching For String Literals

In the quest for localization I need to find all the string literals littered amongst our source code. I was looking for a way to script this into a post-modification source repository check. (I.E. after some one checks something in have a box setup to check this stat) I'll probably use NAnt and CruiseControl or something to handle the m...

Where do Java and .NET string literals reside?

A recent question about string literals in .NET caught my eye. I know that string literals are interned so that different strings with the same value refer to the same object. I also know that a string can be interned at runtime: string now = DateTime.Now.ToString().Intern(); Obviously a string that is interned at runtime resides on t...

Tricky Python string literals in passing parameter to timeit.Timer() function

I'm having a hard time with the setup statement in Python's timeit.Timer(stmt, setup_stmt). I appreciate any help to get me out of this tricky problem: So my sniplet looks like this: def compare(string1, string2): # compare 2 strings if __name__ = '__main__': str1 = "This string has \n several new lines \n in the middle" s...

Are hard-coded STRINGS ever acceptable?

Similar to Is hard-coding literals ever acceptable?, but I'm specifically thinking of "magic strings" here. On a large project, we have a table of configuration options like these: Name Value ---- ----- FOO_ENABLED Y BAR_ENABLED N ... (Hundreds of them). The common practice is to call a generic function to test an ...

Is this really a buffer overflow?

The static analysis tool we use is flagging C code similar to the following as a critical buffer overflow. #define size 64 char buf [size + 1] = ""; memset (buf, 0, size + 1); The tool's error message is: Buffer Overflow (Array Index Out of Bounds): The array 'buf' size is 1. Array 'buf' may use the 0..64 index. Is this legitimat...

How to encode Unicode character codes in a Powershell string literal?

How can I encode the Unicode character U+0048 (H), say, in a Powershell string? In C# I would just do this: "\u0048", but that doesn't appear to work in Powershell. ...

C++ multiline string literal

Is there any way to have multiline plaintext constant literals in C++, ala Perl? Maybe some parsing trick with #includeing a file? I can't think of one, but boy, that would be nice. I know it'll be in C++0x. ...

comparing two strings with 'is' -- not performing as expected

I'm attempting to compare two strings with is. One string is returned by a function, and the other is just declared in the comparison. is tests for object identity, but according to this page, it also works with two identical strings because of Python's memory optimization. But, the following doesn't work: def uSplit(ustring): #...

C/C++, can you #include a file into a string literal?

I have a C++ source file and a Python source file. I'd like the C++ source file to be able to use the contents of the Python source file as a big string literal. I could do something like this: char* python_code = " #include "script.py" " But that won't work because there need to be \'s at the end of each line. I could manually copy a...

Comparing character arrays and string literals in C++

I have a character array and I'm trying to figure out if it matches a string literal, for example: char value[] = "yes"; if(value == "yes") { \\ code block } else { \\ code block } This resulted in the following error: comparison with string literal results in unspecified behaviour. I also tried something like: char value[] = "...

Localization of string literals

I need to localize error messages from a compiler. As it stands, all error messages are spread throughout the source code as string literals in English. We want to translate these error messages into German. What would be the best way to approach this? Leave the string literals as-is, and map the char* to another language inside the erro...

How to convert a string literal into a string value

hi i want to convert a string literal in to string value, can any one guide me in doing that for eg i want o convert the following string literal in to stringvalue. "hello \r\n world" in to "hello world" ...

how to access sys.argv (or any string variable) in raw mode?

I'm having difficulties parsing filepaths sent as arguments: If I type: os.path.normpath('D:\Data2\090925') I get 'D:\\Data2\x0090925' Obviously the \0 in the folder name is upsetting the formatting. I can correct it with the following: os.path.normpath(r'D:\Data2\090925') which gives 'D:\\Data2\\090925' My problem is, how d...

(c/c++) do copies of string literals share memory in TEXT section?

If I call a function like myObj.setType("fluid"); many times in a program, how many copies of the literal "fluid" are saved in memory? Can the compiler recognize that this literal is already defined and just reference it again? ...

Regular expression for a string literal in flex/lex

I'm experimenting to learn flex and would like to match string literals. My code currently looks like: "\""([^\n\"\\]*(\\[.\n])*)*"\"" {/*matches string-literal*/;} I've been struggling with variations for an hour or so and can't get it working the way it should. I'm essentially hoping to match a string literal that can't conta...

C++: Constructor accepting only a string literal

Is it possible to create a constructor (or function signature, for that matter) that only accepts a string literal, but not an e.g. char const *? Is it possible to have two overloads that can distinguish between string literals and char const *? C++ 0x would kind-of allow this with a custom suffix - but I'm looking for an "earlier" sol...

What does assigning a literal string to an NSString with "=" actually do?

Greetings, I'm sure that this is probably an incredibly stupid question, but... What does the following line actually do? string = @"Some text"; Assuming that "string" is declared thusly in the header: NSString *string; What does the "=" actually do here? What does it do to "string"'s reference count? In particular, assuming th...

What are the differences in string literals between C#, Visual Basic.NET, and Managed C++?

I'm referring to the syntax for writing strings in code, including multiline strings and verbatim strings. (Context: I'm working on a tool that scans code, and it's important to determine when tokens are inside a string.) Thanks! ...

What's the u prefix in a python string

Like in: u'Hello' My guess is that it indicates "unicode", is it correct? If so, since when is it available? ...

does javascript have literal strings?

In c# and ruby and many other languages you can denote a string as to not need escaping. in c# its like this string s = @"\whatever\this\is"; the results are when printed \whatever\this\is my question is, is this supported in any form in javascript? ...