Is there some ultra fast "syntax check my code, but don't compile mode" for g++/clang? Where the only goal is to just check if the code I have is valid C++ code?
I'm working on a project that involves parsing a large csv formatted file in Perl and am looking to make things more efficient.
My approach has been to split() the file by lines first, and then split() each line again by commas to get the fields. But this suboptimal since at least two passes on the data are required. (once to split by lines, then once again for each line). This is a very large file, so cutting processing in half would be a significant improvement to the entire application.
My question is, what is the most time efficient means of parsing a large CSV file using only built in tools?
note: Each line has a varying number of tokens, so we can't just ignore lines and split by commas only. Also we can assume fields will contain only alphanumeric ascii data (no special characters or other tricks). Also, i don't want to get into parallel processing, although it might work effectively.
edit
It can only involve built-in tools that ship with Perl 5.8. For bureaucratic reasons, I cannot use any third party modules (even if hosted on cpan)
another edit
Let's assume that our solution is only allowed to deal with the file data once it is entirely loaded into memory.
yet another edit
I just grasped how stupid this question is. Sorry for wasting your time. Voting to close.
Greetings, I'm looking for a way to encode a string into HTML that uses human-readable tags such as ê (=ê). At the moment, I am using the HttpUtility.HtmlEncode() function, but it appears to return numbered tags instead of human-readable ones. For example:
Dim str as string = HttpUtility;HtmlEncode("vente - en-tête")
'Expected: vente - en-tête
'Actually received: vente - en-tête
Is there a setting or function in ASP.Net to encode a string into HTML resembling the first comment?
EDIT: I am looking for this kind of functionality because the text is saved HTML-encoded in the database. The text comes from a bunch of MS Word documents that have been converted to HTML.
info = {'phone_number': '123456', 'personal_detail': {'foo':foo, 'bar':bar}, 'is_active': 1, 'document_detail': {'baz':baz, 'saz':saz}, 'is_admin': 1, 'email': '[email protected]'}
return HttpResponse(simplejson.dumps({'success':'True', 'result':info}), mimetype='application/javascript')
if(data["success"] === "True") {
alert(data[**here I want to display personal_detail and document_details**]);
}
How can I do this?
I have a function of type in_channel -> out_channel -> unit which will output something to an out_channel. Now I'd like to get its output as a string. Creating temporary files to write and read it back seems ugly, so how can I do that? Is there any other methods to create out_channel besides Pervasives.open_out family?
Actually, this function implemented a repl. What I really need is to test it programmatically, so I'd like to first wrap it to a function of type string -> string. For creating the in_channel, it seems I can use Scanf.Scanning.from_string, but I don't know how to create the out_channel parameter.
Hi.
I'm writing a series classes that inherit from a base class using virtual. They are INT, FLOAT and STRING objects that I want to use in a scripting language. I'm trying to implement weak typing, but I don't want STRING objects to return copies of themselves when used in the following way (instead I would prefer to have a reference returned which can be used in copying):
a = "hello ";
b = "world";
c = a + b;
I have written the following code as a mock example:
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
std::string dummy("<int object cannot return string reference>");
struct BaseImpl
{
virtual bool is_string() = 0;
virtual int get_int() = 0;
virtual std::string get_string_copy() = 0;
virtual std::string const& get_string_ref() = 0;
};
struct INT : BaseImpl
{
int value;
INT(int i = 0) : value(i)
{
std::cout << "constructor called\n";
}
INT(BaseImpl& that) : value(that.get_int())
{
std::cout << "copy constructor called\n";
}
bool is_string() { return false; }
int get_int()
{
return value;
}
std::string get_string_copy()
{
char buf[33];
sprintf(buf, "%i", value);
return buf;
}
std::string const& get_string_ref()
{
return dummy;
}
};
struct STRING : BaseImpl
{
std::string value;
STRING(std::string s = "") : value(s)
{
std::cout << "constructor called\n";
}
STRING(BaseImpl& that)
{
if (that.is_string())
value = that.get_string_ref();
else
value = that.get_string_copy();
std::cout << "copy constructor called\n";
}
bool is_string() { return true; }
int get_int()
{
return atoi(value.c_str());
}
std::string get_string_copy()
{
return value;
}
std::string const& get_string_ref()
{
return value;
}
};
struct Base
{
BaseImpl* impl;
Base(BaseImpl* p = 0) : impl(p) {}
~Base() { delete impl; }
};
int main()
{
Base b1(new INT(1));
Base b2(new STRING("Hello world"));
Base b3(new INT(*b1.impl));
Base b4(new STRING(*b2.impl));
std::cout << "\n";
std::cout << b1.impl->get_int() << "\n";
std::cout << b2.impl->get_int() << "\n";
std::cout << b3.impl->get_int() << "\n";
std::cout << b4.impl->get_int() << "\n";
std::cout << "\n";
std::cout << b1.impl->get_string_ref() << "\n";
std::cout << b2.impl->get_string_ref() << "\n";
std::cout << b3.impl->get_string_ref() << "\n";
std::cout << b4.impl->get_string_ref() << "\n";
std::cout << "\n";
std::cout << b1.impl->get_string_copy() << "\n";
std::cout << b2.impl->get_string_copy() << "\n";
std::cout << b3.impl->get_string_copy() << "\n";
std::cout << b4.impl->get_string_copy() << "\n";
return 0;
}
It was necessary to add an if check in the STRING class to determine whether its safe to request a reference instead of a copy:
Script code:
a = "test";
b = a;
c = 1;
d = "" + c; /* not safe to request reference by standard */
C++ code:
STRING(BaseImpl& that)
{
if (that.is_string())
value = that.get_string_ref();
else
value = that.get_string_copy();
std::cout << "copy constructor called\n";
}
If was hoping there's a way of moving that if check into compile time, rather than run time.
heres what i did, i just have ne error that i cant figure out.
int mystrlen(char string[])
{
char string1[LENGHT], string2[LENGHT];
int len1, len2;
char newstring[LENGHT*2];
printf("enter first string:\n");
len1 = mystrlen(string1);
printf("enter second string:\n");
len2 = mystrlen(string2);
if(len1 == EOF || len2 == EOF)
exit(1);
strcpy(newstring, string1);
strcat(newstring, string2);
printf("%s\n", newstring);
return 0;
A while back I created a licensing system for my companies new product, as well as all products after this one. As with a lot of licensing systems mine generates codes: 25 character product and registration codes, as well as 16 character module unlocking codes.
My question is, since some parts of these generated codes are random should I apply a language filter to it to avoid any embarrassing language being given to the end users?
I chose to as it was not difficult at all.
But has anyone else ever came across something like this? Any viewpoints as to if it is worth the effort?
I'm interested in presenting results faster in my mobile app. Is it possible to stream results out as the string downloads? I'm thinking about implementing an IObservable to push out the results as they are downloaded, but I don't know what algorithm to use to properly piece together the data which could be incomplete at any given point.
Hope that was clear enough.
CLARIFICATION: Guess it wasn't clear enough. My issue is the string downloaded is quite long. It can often take 15-20 seconds or more to download. I want to reflect changes faster to my user, so I would like to use reactive extensions to pump out entities as soon as a complete one is received.
My issue is I dont know how to build the parser that can pick out complete entities from an incomplete response string.
In silverlight, can you bind to a property that contains parameter? For example, the following doesn’t seem to work. Am I missing something or is this not possible?
C#
private System.Collections.Generic.Dictionary<string, string> ValuesField = new System.Collections.Generic.Dictionary<string, string>();
public string Value {
get { return ValuesField(FieldName); }
set { ValuesField(FieldName) = value; }
}
VB
Private ValuesField As New System.Collections.Generic.Dictionary(Of String, String)
Public Property Value(ByVal FieldName As String) As String
Get
Return ValuesField(FieldName)
End Get
Set(ByVal value As String)
ValuesField(FieldName) = value
End Set
End Property
XAML
<TextBox Name="TextBox1" VerticalAlignment="Top" Width="120"Text="{Binding Path=Value[MyField],Mode=TwoWay }" />
Hi,
I'm getting result sets from Sybase that I return to a C# client.
I use the below function to write the result set data to Excel:
***private static void WriteData(Excel.Worksheet worksheet, string cellRef, ref string[,] data)
{
Excel.Range range = worksheet.get_Range(cellRef, Missing.Value);
if (data.GetLength(0) != 0)
{
range = range.get_Resize(data.GetLength(0), data.GetLength(1));
range.set_Value(Missing.Value, data);
}
}*
The data gets written correctly.
The issue is that since I'm using string array to write data (which is a mixture of strings and floats), Excel highlights every cell that contains numeric data with the message "Number Stored as Text".
How do I get rid of this issue?
Many thanks,
Chapax
For my application, I need to be able to send an std::vector<std::string> over a UNIX socket(local), and get a copy of the vector on the other end of the socket. What's the easiest way to do this with O(1) messages relative to the size of the vector(i.e. without sending a message for each string in the vector)?
Since this is all on the same host, and because I control both ends of the socket, I'm not concerned with machine-specific issues such as endinness or vector/string representation.
I'm not sure if I worded the title correctly.
Basically is it possible to treat a string as HTML as if it was on the page? So I can use $("#elem") and all the other jQuery functions?
The HTML is loaded into a string from an ajax request and stored in a string. Instead of using regular expressions to access the data needed is it possible to use jQuery functions?
ajaxTextResponse.$("#telephone");
I know the above won't work, but you see what I am getting at.
Thanks
I have some messages being passed back from my server through php. The problem is that the messages are in English and if the user is using another language they will still get the message in English.
So I had an idea that maybe instead of passing back the message I would instead pass the String resource Id from the android app, that way the app will get the correct string id for their language. I will use this in a number of apps so I just want to know if the string id is guaranteed to be the same across different android projects?
Hi,
I'm trying to evaluate an xpath varable I'm building dynamically based on the position of the node.
I can create the xpath string in a variable but when I select the value of this just get the string and not the node set I need.
I use the following to create the xpath
<xsl:variable name="xpathstring" select="normalize-space(concat("//anAttribute[@key='pos",position(),"']"))"/>
and try to output the value with the following.
<xsl:value-of select="$xpathstring"/>
If I execute the xpath in my debugger I get the nodeset but in my xml output only get the xpath string which looks like this //anAttribute[@key='pos1']
I had a look at exslt dyn:evaluate which seems to enable this but this seems to be only supported by certain processors and doesn't provide a standalone implementation or at least as far as I could see (currently using the standard .net 2.0 xslt whihc is only xslt 1.0 as far as I recall)
Is there anyway to handle this without changing processor?
Kind Regards,
Crocked
I finished installing Ubuntu 10 for netbooks, and XAMPP. The XAMPP website tutorial made it very easy to install, then left me high and dry. Everything works, but I have no idea where to put my handwritten php files.
After a few hours of googling, and trying to understand the file explorer, I realized I have no idea where anything is in ubuntu. For an answer, please don't just tell me "go to "X" directory. I won't know how to navigate there.
I also did a file search for htdocs with no luck.
I have data that looks like this:
#info
#info2
1:SRX004541
Submitter: UT-MGS, UT-MGS
Study: Glossina morsitans transcript sequencing project(SRP000741)
Sample: Glossina morsitans(SRS002835)
Instrument: Illumina Genome Analyzer
Total: 1 run, 8.3M spots, 299.9M bases
Run #1: SRR016086, 8330172 spots, 299886192 bases
2:SRX004540
Submitter: UT-MGS
Study: Anopheles stephensi transcript sequencing project(SRP000747)
Sample: Anopheles stephensi(SRS002864)
Instrument: Solexa 1G Genome Analyzer
Total: 1 run, 8.4M spots, 401M bases
Run #1: SRR017875, 8354743 spots, 401027664 bases
3:SRX002521
Submitter: UT-MGS
Study: Massive transcriptional start site mapping of human cells under hypoxic conditions.(SRP000403)
Sample: Human DLD-1 tissue culture cell line(SRS001843)
Instrument: Solexa 1G Genome Analyzer
Total: 6 runs, 27.1M spots, 977M bases
Run #1: SRR013356, 4801519 spots, 172854684 bases
Run #2: SRR013357, 3603355 spots, 129720780 bases
Run #3: SRR013358, 3459692 spots, 124548912 bases
Run #4: SRR013360, 5219342 spots, 187896312 bases
Run #5: SRR013361, 5140152 spots, 185045472 bases
Run #6: SRR013370, 4916054 spots, 176977944 bases
What I want to do is to create a hash of array with first line of each chunk as keys
and SR## part of lines with "^Run" as its array member:
$VAR = {
'SRX004541' => ['SRR016086'],
# etc
}
But why my construct doesn't work. And it must be a better way to do it.
use Data::Dumper;
my %bighash;
my $head = "";
my @temp = ();
while ( <> ) {
chomp;
next if (/^\#/);
if ( /^\d{1,2}:(\w+)/ ) {
print "$1\n";
$head = $1;
}
elsif (/^Run \#\d+: (\w+),.*/){
print "\t$1\n";
push @temp, $1;
}
elsif (/^$/) {
push @{$bighash{$head}}, [@temp];
@temp =();
}
}
print Dumper \%bighash ;
I noticed that .NET framework uses formatting functions, generated the same way localizable string are.
There is a resource file Resources.resx with resource string TestString. So you may use it in code like this:
string localizableValue = Resources.TestString;
Now, imagine you need a formattable localizable string, to use it in string.Format function. So everytime you use it, you have to write something like this:
string localizableFormattedValue = string.Format(Resources.TestFormatString, someParam1, someParam2);
The observation says that in .NET framework generated resource classes already include the above construction. So instead of string property, a string function is generated. The resulting code looks like this:
string localizableFormattedValue = Resources.TestFormatString(someParam1, someParam2);
The question is - how do they do this? Is it some custom Microsoft feature (resx generator) or I'm missing something obvious?
I have a var dump of my sql query which return the following
I wanna to count in the array below that how many rows of myID = 5 are there. How would I do that. I am using php. Thanks in advance
array
0 =
object(stdClass)[17]
public 'myID' => string '5' (length=1)
public 'data' => string '123' (length=3)
1 =
object(stdClass)[18]
public 'myID' => string '5' (length=1)
public 'data' => string '123' (length=3)
2 =
object(stdClass)[19]
public 'relativeTypeID' => string '2' (length=1)
public 'data' => string '256' (length=3)
3 =
object(stdClass)[20]
public 'myID' => string '4' (length=1)
public 'data' => string '786' (length=3)
object(stdClass)[21]
public 'myID' => string '4' (length=1)
public 'data' => string '786' (length=3)
I'm new to using sockets. I have a very basic client that sends a request, and waits for a response. The response is one stream, but has two parts. The first part is prefixed with ANS and is a set of key/value pairs in this form: KEY:Value with each pair on a separate line.
The second part of the response is prefixed by RCT and this is pre-formatted text that needs to be send directly to a printer.
So what would be the best way to extract both parts of the response, and in the first part, get each Key:Value pair. I might not even need them all, but I have to look at each one to see what the values are then decide what to do with it.
I'm currently writing the response out to a textbox just to understand what its doing, but now I need to actually do something with the data.
Here's a data sample, as it is received:
ANS Result: Data Received
RCPRES:Q[81]
TML:123
OPP:
MRR:000000999999
<several dozen more KEY:Value pairs>
RCTNov 05 2013 04:03 pm Trans# 123456
<pre-formatted text>
Hello SO;
I've been fighting with this problem all day and am just about at my wit's end.
I have an XML file in which certain portions of data are stored as escaped text but are themselves well-formed XML. I want to convert the whole hierarchy in this text node to a node-set and extract the data therein. No combination of variables and functions I can think of works.
The way I'd expect it to work would be:
<xsl:variable name="a" select="InnerXML">
<xsl:for-each select="exsl:node-set($a)/*">
'do something
</xsl:for-each>
The input element InnerXML contains text of the form
<root><element a>text</element a><element b><element c/><element d>text</element d></element b></root>
but that doesn't really matter. I just want to navigate the xml like a normal node-set.
Where am I going wrong?
I need to be able to remove non-XHTML tags from a string containing XHTML that has been stored in a database. The string also contains references for controls (e.g. ) inside the XHTML, but I need clean XHTML with all standard tag contents unchanged.
These control tags are varied (they could be any ASP.NET control), so there are too many to go looking for each one and remove them. The way they are closed is also varied, so not all of them have closing tags, some are self closing.
How can I go about doing this? I've found some HTML cleaners on-line for including in my project, but they either remove everything or just HTML encode the entire string.
Also, I'm dealing with parts of XHTML documents, not entire documents - don't know if that makes a difference.
Any help would be appreciated.
I want to be able to be able to quickly cast an array of objects to a different type, such as String, but the following code doesn't work:
String[] a = new String[2];
a[0] = "Hello";
a[1] = "World";
ArrayList b = new ArrayList(a);
String[] c = (String[]) b.ToArray();
And I don't want to have to do this:
String[] a = new String[2];
a[0] = "Hello";
a[1] = "World";
ArrayList b = new ArrayList(a);
Object[] temp = b.ToArray();
Object[] temp = b.ToArray();
String[] c = new String[temp.Length];
for(int i=0;i<temp.Length;i++)
{
c[i] = (String) temp[i];
}
Is there an easy way to do this without using a temporary variable?