Search Results

Search found 6715 results on 269 pages for 'preg match'.

Page 85/269 | < Previous Page | 81 82 83 84 85 86 87 88 89 90 91 92  | Next Page >

  • Having trouble creating vectors of System::String^

    - by Justen
    So I have a regex expression to parse certain parts of a file name. I'm trying to store each part in its own vector until I use it later, but it won't let me. One error I get when I try making a vector of System::String^ is that error C3698: 'System::String ^' : cannot use this type as argument of 'new' Then, when I try just making a vector of std::string, it can't implicitly convert to type System::String^, and casting won't work either. void parseData() { System::String^ pattern = "(\\D+)(\\d+)(\\w{1})(\\d+)\\.(\\D{3})"; std::vector < System::String^ > x, y, filename, separator; Regex re( pattern ); for ( int i = 0; i < openFileDialog1->FileNames->Length; i++ ) { Match^ m = re.Match( openFileDialog1->FileNames[i] ); filename.push_back( m->Groups[0]->Value );/* x.push_back( m->Groups[1]->Value ); separator.push_back( m->Groups[2]->Value ); y.push_back( m->Groups[3]->Value );*/ } }

    Read the article

  • Something confusing about FormsOf (Sql server Full-Text searching)

    - by AspOnMyNet
    hi I'm using Sql Server 2008 1) A given <simple_term> within a <generation_term> will not match both nouns and verbs. If I understand the above text correctly, then query SELECT * FROM someTable WHERE CONTAINS ( *, ' FORMSOF ( INFLECTIONAL, park ) ' ) should search for either nouns or verbs derived from the root word “park”, but not for both? Thus out of the two rows, one containing noun parks and other verb parking, the above query should return just one of the two rows? But as it turns out, query returns both rows, so are perhaps my assumptions a bit off or is the above quote wrong?! 2) From Msdn: If freetext_string is enclosed in double quotation marks, a phrase match is instead performed; stemming and thesaurus are not performed. According to the above quote the following query shouldn’t return rows containing strings surfing ( due to query not performing stemming ), surf ( due to query performing phrase matching and not individual word matching ) and surfing with suzy’s sister ( due to query not performing stemming and due to query performing phrase matching and not word matching ), but it does. Thus, it appears that even when *freetext_string* is enclosed in double quotation marks, stemming is still preformed, while phrase matching is not: SELECT * FROM someTable WHERE FREETEXT( *, ' "surf sister" ' ) So is the above quote wrong or...? thanx

    Read the article

  • Ruby Design Problem for SQL Bulk Inserter

    - by crunchyt
    This is a Ruby design problem. How can I make a reusable flat file parser that can perform different data scrubbing operations per call, return the emitted results from each scrubbing operation to the caller and perform bulk SQL insertions? Now, before anyone gets narky/concerned, I have written this code already in a very unDRY fashion. Which is why I am asking any Ruby rockstars our there for some assitance. Basically, everytime I want to perform this logic, I create two nested loops, with custom processing in between, buffer each processed line to an array, and output to the DB as a bulk insert when the buffer size limit is reached. Although I have written lots of helpers, the main pattern is being copy pasted everytime. Not very DRY! Here is a Ruby/Pseudo code example of what I am repeating. lines_from_file.each do |line| line.match(/some regex/).each do |sub_str| # Process substring into useful format # EG1: Simple gsub() call # EG2: Custom function call to do complex scrubbing # and matching, emitting results to array # EG3: Loop to match opening/closing/nested brackets # or other delimiters and emit results to array end # Add processed lines to a buffer as SQL insert statement @buffer << PREPARED INSERT STATEMENT # Flush buffer when "buffer size limit reached" or "end of file" if sql_buffer_full || last_line_reached @dbc.insert(SQL INSERTS FROM BUFFER) @buffer = nil end end I am familiar with Proc/Lambda functions. However, because I want to pass two separate procs to the one function, I am not sure how to proceed. I have some idea about how to solve this, but I would really like to see what the real Rubyists suggest? Over to you. Thanks in advance :D

    Read the article

  • Counting problem C#

    - by MadBoy
    Hello, I've a bit of a problem. I'm adding numbers to ArrayList like 156, 340 (when it is TransferIn or Buy) etc and then i remove them doing it like 156, 340 (when it's TransferOut, Sell). Following solution works for that without a problem. The problem I have is that for some old data employees were entering sum's like 1500 instead of 500+400+100+500. How would I change it so that when there's Sell/TransferOut and there's no match inside ArrayList it should try to add multiple items from that ArrayList and find elements that combine into aggregate. ArrayList alNew = new ArrayList(); ArrayList alNewPoIle = new ArrayList(); ArrayList alNewCo = new ArrayList(); string tempAkcjeCzynnosc = (string) alInstrumentCzynnoscBezNumerow[i]; string tempAkcjeInId = (string) alInstrumentNazwaBezNumerow[i]; decimal varAkcjeCena = (decimal) alInstrumentCenaBezNumerow[i]; decimal varAkcjeIlosc = (decimal) alInstrumentIloscBezNumerow[i]; int index; switch (tempAkcjeCzynnosc) { case "Sell": case "TransferOut": index = alNew.IndexOf(varAkcjeIlosc); if (index != -1) { alNew.RemoveAt(index); alNewPoIle.RemoveAt(index); alNewCo.RemoveAt(index); } else { // Number without match encountred } break; case "Buy": case "TransferIn": alNew.Add(varAkcjeIlosc); alNewPoIle.Add(varAkcjeCena); alNewCo.Add(tempAkcjeInId); break; } }

    Read the article

  • How do I refactor code into a subroutine but allow for early exit?

    - by deworde
    There's a really obvious refactoring opportunity in this (working) code. bool Translations::compatibleNICodes(const Rule& rule, const std::vector<std::string>& nicodes) { bool included = false; // Loop through the ni codes. for(std::vector<std::string> iter = nicodes.begin(); iter != nicodes.end(); ++iter) { // Match against the ni codes of the rule if(rule.get_ni1() == *iter) { // If there's a match, check if the rule is include or exclude const std::string flag = rule.get_op1(); // If include, code is included unless a later rule excludes it if(flag == "INCLUDE"){ included = true; } // If exclude, code is specifically excluded else if(flag == "EXCLUDE"){ return false; } } if(rule.get_ni2() == *iter) { const std::string flag = rule.get_op2(); if(flag == "INCLUDE"){ included = true; } else if(flag == "EXCLUDE"){ return false; } } if(rule.get_ni3() == *iter) { const std::string flag = rule.get_op3(); if(flag == "INCLUDE"){ included = true; } else if(flag == "EXCLUDE"){ return false; } } if(rule.get_ni4() == *iter) { const std::string flag = rule.get_op4(); if(flag == "INCLUDE"){ included = true; } else if(flag == "EXCLUDE"){ return false; } } if(rule.get_ni5() == *iter) { const std::string flag = rule.get_op5(); if(flag == "INCLUDE"){ included = true; } else if(flag == "EXCLUDE"){ return false; } } } return included; } The problem is that I can't get around the problem that I want to exit early if it's an exclude statement. Note that I can't change the structure of the Rule class. Any advice?

    Read the article

  • Using Python to get a CSV output for the following example.

    - by Az
    Hi there, I'm back again with my ongoing saga of Student-Project Allocation questions. Thanks to Moron (who does not match his namesake) I've got a bit of direction for an evaluation portion of my project. Going with the idea of the Assignment Problem and Hungarian Algorithm I would like to express my data in the form of a .csv file which would end up looking like this in spreadsheet form. This is based on the structure I saw here. | | Project 1 | Project 2 | Project 3 | |----------|-----------|-----------|-----------| |Student1 | | 2 | 1 | |----------|-----------|-----------|-----------| |Student2 | 1 | 2 | 3 | |----------|-----------|-----------|-----------| |Student3 | 1 | 3 | 2 | |----------|-----------|-----------|-----------| To make it less cryptic: the rows are the Students/Agents and the columns represent Projects/Task. Obviously ONE project can be assigned to ONE student. That, in short, is what my project is about. The fields represent the preference weights the students have placed upon the projects (ranging from 1 to 10). If blank, that student does not want that project and there's no chance of him/her being assigned such. Anyway, my data is stored within dictionaries. Specifically the students and projects dictionaries such that: students[student_id] = Student(student_id, student_name, alloc_proj, alloc_proj_rank, preferences) where preferences is in the form of a dictionary such that preferences[rank] = {project_id} and projects[project_id] = Project(project_id, project_name) I'm aware that sorted(students.keys()) will give me a sorted list of all the student IDs which will populate the row labels and sorted(projects.keys()) will give me the list I need to populate the column labels. Thus for each student, I'd go into their preferences dictionary and match the applicable projects to ranks. I can do that much. Where I'm failing is understanding how to create a .csv file. Any help, pointers or good tutorials will be highly appreciated.

    Read the article

  • MySQL: Complex Join Statement involving two tables and a third correlation table

    - by Stephen
    I have two tables that were built for two disparate systems. I have records in one table (called "leads") that represent customers, and records in another table (called "manager") that are the exact same customers but "manager" uses different fields (For example, "leads" contains an email address, and "manager" contains two fields for two different emails--either of which might be the email from "leads"). So, I've created a correlation table that contains the lead_id and manager_id. currently this correlation table is empty. I'm trying to query the "leads" table to give me records that match either "manager" email field with the single "leads" email field, while at the same time ignoring fields that have already been added to the "correlated" table. (this way I can see how many leads that match have not yet been correlated.) Here's my current, invalid SQL attempt: SELECT leads.id, manager.id FROM leads, manager LEFT OUTER JOIN correlation ON correlation.lead_id = leads.id WHERE correlation.id IS NULL AND leads.project != "someproject" AND (manager.orig_email = leads.email OR manager.dest_email = leads.email) AND leads.created BETWEEN '1999-01-01 00:00:00' AND '2010-05-10 23:59:59' ORDER BY leads.created ASC; I get the error: Unknown column 'leads.id' in 'on clause' Before you wonder: there are records in the "leads" table where leads.project != "someproject" and leads.created falls between those dates. I've included those additional parameters for completeness.

    Read the article

  • Matching several items inside one string with preg_match_all() and end characters

    - by nefo_x
    I have the following code: preg_match_all('/(.*) \((\d+)\) - ([\d\.\d]+)[,?]/U', "E-Book What I Didn't Learn At School... (2) - 3525.01, FREE Intro DVD/Vid (1) - 0.15", $match); var_dump($string, $match); and get the following ouput: array(4) { [0]=> array(1) { [0]=> string(54) "E-Book What I Didn't Learn At School... (2) - 3525.01," } [1]=> array(1) { [0]=> string(39) "E-Book What I Didn't Learn At School..." } [2]=> array(1) { [0]=> string(1) "2" } [3]=> array(1) { [0]=> string(7) "3525.01" } } which matches only one items... what i need is to get all items from such strings. when i've added "," sign to the end of the string - it worked fine. but that is non-sense in adding comma to each string. Any advice?

    Read the article

  • Custom Solr sorting

    - by Tom
    Hello everyone, I've been asked to do an evaluation of Solr as an alternative for a commercial search engine. The application now has a very particular way of sorting results using something called "buckets". I'll try to explain with a bit of details: In the interface they have 2 fields: "what" and "where". Both fields are actually sets of fields (what = category, name, contact info... and where= country, state, region, city...) so the copyfield feature of Solr immediately comes to mind. Now based on the field generated the actual match the result should end up in a specific bucket. In particular the first bucket contains all the result documents that have an exact match on the category field, in the second bucket all exact matches on name, the third partial matches on category, the fourth partial matches on name, the fifth matches on contact info etc... Then within each of those first tier buckets all results are placed in second tier buckets depending on what location was matched: city, then region, then province and so on. To even complicate things more there is also a third tier bucket where results are placed according to the value of a ranking field: all documents with the value 1 in the ranking field go in bucket 1 and so on. And finally results should be randomized in the third tier bucket... On top of this they obviously want support for facets and paging. My apologies for the long mail but I would greatly appreciate feedback and/or suggestions. I'm aware that this that this is a very particular problem but everything that points me in the right direction is helpful. Cheers, Tom

    Read the article

  • How do I best do balanced quoting with Perl's Regexp::Grammars?

    - by Evan Carroll
    Using Damian Conway's Regexp::Grammars, I'm trying to match different balanced quoting ('foo', "foo", but not 'foo") mechanisms -- such as parens, quotes, double quotes, and double dollars. This is the code I'm currently using. <token: pair> \'<literal>\'|\"<literal>\"|\$\$<literal>\$\$ <token: literal> [\S]+ This generally works fine and allows me to say something like: <rule: quote> QUOTE <.as>? <pair> My question is how do I reform the output, to exclude the needles notation for the pair token? { '' => 'QUOTE AS \',\'', 'quote' => { '' => 'QUOTE AS \',\'', 'pair' => { 'literal' => ',', '' => '\',\'' } } }, Here, there is obviously no desire to have pair in between, quote, and the literal value of it. Is there a better way to match 'foo', "foo", and $$foo$$, and maybe sometimes ( foo ) without each time creating a needless pair token? Can I preprocess-out that token or fold it into the above? Or, write a better construct entirely that eliminates the need for it?

    Read the article

  • Help me to refactor this F# code to tail recursion

    - by Kev
    I write some code to learning F#. Here is a example: let nextPrime list= let rec loop n= match n with | _ when (list |> List.filter (fun x -> x <= ( n |> double |> sqrt |> int)) |> List.forall (fun x -> n % x <> 0)) -> n | _ -> loop (n+1) loop (List.max list + 1) let rec findPrimes num= match num with | 1 -> [2] | n -> let temp = findPrimes <| n-1 (nextPrime temp ) :: temp //find 10 primes findPrimes 10 |> printfn "%A" I'm very happy that it just works! I'm totally beginner to recursion Recursion is a wonderful thing. I think findPrimes is not efficient. Someone help me to refactor findPrimes to tail recursion if possible? BTW, is there some more efficient way to find first n primes?

    Read the article

  • Why don't copy this dokument attributes from the source xml file??

    - by siegfried storr
    Hi anyone, i'm working the first time with xslt and i really don't understand why this xsl don't copy attributes from the source xml. Perhaps someone can give me a hint?? <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:variable name="rpl" select="document('ParamInvoice.xml')"/> <xsl:template match="/"> <xsl:copy> <xsl:apply-templates select="* | @*"/> </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:variable name="vInvoiceElement" select="$rpl/StoraInvoice/*[name()=name(current())]"/> <xsl:copy> <xsl:if test="$vInvoiceElement/Attribute"> <xsl:call-template name="AttributeErzeugen"> <xsl:with-param name="pAttr" select="$vInvoiceElement/Attribute"/> </xsl:call-template> </xsl:if> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template name="AttributeErzeugen"> <xsl:param name="pAttr"/> <xsl:for-each select="$pAttr"> <xsl:attribute name="{@name}"><xsl:value-of select="."/></xsl:attribute> </xsl:for-each> </xsl:template> </xsl:stylesheet>

    Read the article

  • resizing images with imagemagick via shell script

    - by jml
    Hi there, I don't really know that much about bash scripts OR imagemagick, but I am attempting to create a script in which you can give some sort of regexp matching pattern for a list of images and then process those into new files that have a given filename prefix. for example given the following dir listing: allfiles01.jpg allfiles02.jpg allfiles03.jpg i would like to call the script like so: ./resisemany.sh allfiles*.jpg 30 newnames*.jpg the end result of this would be that you get a bunch of new files with newnames, the numbers match up, so far what i have is: IMAGELIST=$1 RESIEZFACTOR=$2 NUMIMGS=length($IMAGELIST) for(i=0; i<NUMIMGS; i++) convert $IMAGELIST[i] -filter bessel -resize . RESIZEFACTOR . % myfile.JPG Thanks for any help... The parts that I obviously need help with are 1. how to give a bash script matching criteria that it understands 2. how to use the $2 without having it match the 2nd item in the image list 3. how to get the length of the image list 4. how to create a proper for loop in such a case 5. how to do proper text replacement for a shell command whereby you are appending items as i allude to. jml

    Read the article

  • Beginner Question: For extract a large subset of a table from MySQL, how does Indexing, order of tab

    - by chongman
    Sorry if this is too simple, but thanks in advance for helping. This is for MySQL but might be relevant for other RDMBSs tblA has 4 columns: colA, colB, colC, mydata, A_id It has about 10^9 records, with 10^3 distinct values for colA, colB, colC. tblB has 3 columns: colA, colB, B_id It has about 10^4 records. I want all the records from tblA (except the A_id) that have a match in tblB. In other words, I want to use tblB to describe the subset that I want to extract and then extract those records from tblA. Namely: SELECT a.colA, a.colB, a.colC, a.mydata FROM tblA as a INNER JOIN tblB as b ON a.colA=b.colA a.colB=b.colB ; It's taking a really long time (more than an hour) on a newish computer (4GB, Core2Quad, ubuntu), and I just want to check my understanding of the following optimization steps. ** Suppose this is the only query I will ever run on these tables. So ignore the need to run other queries. Now my questions: 1) What indexes should I create to optimize this query? I think I just need a multiple index on (colA, colB) for both tables. I don't think I need separate indexes for colA and colB. Another stack overflow article (that I can't find) mentioned that when adding new indexes, it is slower when there are existing indexes, so that might be a reason to use the multiple index. 2) Is INNER JOIN correct? I just want results where a match is found. 3) Is it faster if I join (tblA to tblB) or the other way around, (tblB to tblA)? This previous answer says that the optimizer should take care of that. 4) Does the order of the part after ON matter? This previous answer say that the optimizer also takes care of the execution order.

    Read the article

  • Using javascript and php together

    - by EmmyS
    I have a PHP form that needs some very simple validation on submit. I'd rather do the validation client-side, as there's quite a bit of server-side validation that happens to deal with writing form values to a database. So I just want to call a javascript function onsubmit to compare values in two password fields. This is what I've got: function validate(form){ var password = form.password.value; var password2 = form.password2.value; alert("password:"+password+" password2:" + password2); if (password != password2) { alert("not equal"); document.getElementByID("passwordError").style.display="inline"; return false; } alert("equal"); return true; } The idea being that a default-hidden div containing an error message would be displayed if the two passwords don't match. The alerts are just to display the values of password and password2, and then again to indicate whether they match or not (will not be used in production code). I'm using an input type=submit button, and calling the function in the form tag: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return validate(this);"> Everything is alerting as expected when entering non-matching values. I would have hoped (and assumed, based on past use) that if the function returned false, the actual submit would not occur. And yet, it is. I'm testing by entering non-matching values in the password fields, and the alerts clearly show me the values and the not equal result, but the actual form action is still occurring and it's trying to write to my database. I'm pretty new at PHP; is there something about it that will not let me combine with javascript this way? Would it be better to use an input type=button and include submit() in the function itself if it returns true?

    Read the article

  • Use Javascript RegEx to extract column names from SQLite Create Table SQL

    - by NimbusSoftware
    I'm trying to extract column names from a SQLite result set from sqlite_master's sql column. I get hosed up in the regular expressions in the match() and split() functions. t1.executeSql('SELECT name, sql FROM sqlite_master WHERE type="table" and name!="__WebKitDatabaseInfoTable__";', [], function(t1, result) { for(i = 0;i < result.rows.length; i++){ var tbl = result.rows.item(i).name; var dbSchema = result.rows.item(i).sql; // errors out on next line var columns = dbSchema.match(/.*CREATE\s+TABLE\s+(\S+)\s+\((.*)\).*/)[2].split(/\s+[^,]+,?\s*/); } }, function(){console.log('err1');} ); I want to parse SQL statements like these... CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE tblConfig (Key TEXT NOT NULL,Value TEXT NOT NULL); CREATE TABLE tblIcon (IconID INTEGER NOT NULL PRIMARY KEY,png TEXT NOT NULL,img32 TEXT NOT NULL,img64 TEXT NOT NULL,Version TEXT NOT NULL) into a strings like theses... name,seq Key,Value IconID,png,img32,img64,Version Any help with a RegEx would be greatly appreciated.

    Read the article

  • Sql Server Compact Edition version error.

    - by Tim
    I am working on .NET ClickOnce project that uses Sql Server 2005 Compact Edition to synchronize remote data through the use of a Merge replication. This application has been live for nearly a year now, and while we encounter occasional synchronization errors, things run quite smoothly for the most part. Yesterday a user reported an error that I have never seen before and have yet to find any information for online. Many users synchronize every night, and I haven't received error reports from anyone else, so this issue must be isolated to this particular user / client machine. Here are the full details of the error: -Error Code : 80004005 -Message : The message contains an unexpected replication operation code. The version of SQL Server Compact Edition Client Agent and SQL Server Compact Edition Server Agent should match. [ replication operation code = 31 ] -Minor Error : 28526 -Source : Microsoft SQL Server Compact Edition -Numeric Parameters : 31 One interesting thing that I've found is that his data does get synchronized to the server, so this error must occur after the upload completes. I have yet to determine whether or not changes at the server are still being downloaded to his subscription. Thinking that maybe there was some kind of version conflict going on, I had a remote desktop session with this user last night and uninstalled both the application and the SQL Server Compact Edition prerequisite, then reinstalled both from our ClickOnce publication site. I also removed his existing local database file so that upon synchronization, an entirely new subscription would be issued to him. Still his errors continue. I suppose the error may be somewhat general, and the text in the error message stating that the versions should match may not necessarily reflect the problem at hand. This site contains the only official reference to this error that I've been able to find, and it offers no more detail than the error message itself. Has anyone else encountered this error? Or at least know more about SQL Compact to have a better guess as to what is going on here? Any help / suggestions will be greatly appreciated!

    Read the article

  • Jquery resizing image

    - by michele
    I'd like to start a discussion about the image resizing using jQuery. That's my contribution: But I think I'm far away from the solution. What about the cropping? Who can help me? $(document).ready(function() { $('.story-small img').each(function() { var maxWidth = 100; // Max width for the image var maxHeight = 100; // Max height for the image var ratio = 0; // Used for aspect ratio var width = $(this).width(); // Current image width var height = $(this).height(); // Current image height // Check if the current width is larger than the max if(width > maxWidth){ ratio = maxWidth / width; // get ratio for scaling image $(this).css("width", maxWidth); // Set new width $(this).css("height", height * ratio); // Scale height based on ratio height = height * ratio; // Reset height to match scaled image } // Check if current height is larger than max if(height > maxHeight){ ratio = maxHeight / height; // get ratio for scaling image $(this).css("height", maxHeight); // Set new height $(this).css("width", width * ratio); // Scale width based on ratio width = width * ratio; // Reset width to match scaled image } }); });

    Read the article

  • Which text margin does SWT Table use when drawing text?

    - by Zordid
    I got a relatively easy question - but I cannot find anything anywhere to answer it. I use a simple SWT table widget in my application that displays only text in the cells. I got an incremental search feature and want to highlight text snippets in all cells if they match. So when typing "a", all "a"s should be highlighted. To get this, I add an SWT.EraseItem listener to interfere with the background drawing. If the current cell's text contains the search string, I find the positions and calculate relative x-coordinates within the text using event.gc.stringExtent - easy. With that I just draw rectangles "behind" the occurrences. Now, there's a flaw in this. The table does not draw the text without a margin, so my x coordinate does not really match - it is slightly off by a few pixels! But how many?? Where do I retrieve the cell's text margins that table's own drawing will use? No clue. Cannot find anything. :-( Bonus question: the table's draw method also shortens text and adds "..." if it does not fit into the cell. Hmm. My occurrence finder takes the TableItem's text and thus also tries to mark occurrences that are actually not visible because they are consumed by the "...". How do I get the shortened text and not the "real" text within the EraseItem draw handler? Thanks!

    Read the article

  • Boost Binary Endian parser not working?

    - by Hai
    I am studying how to use boost spirit Qi binary endian parser. I write a small test parser program according to here and basics examples, but it doesn't work proper. It gave me the msg:"Error:no match". Here is my code. #include "boost/spirit/include/qi.hpp" #include "boost/spirit/include/phoenix_core.hpp" #include "boost/spirit/include/phoenix_operator.hpp" #include "boost/spirit/include/qi_binary.hpp" // parsing binary data in various endianness template '<'typename P, typename T void binary_parser( char const* input, P const& endian_word_type, T& voxel, bool full_match = true) { using boost::spirit::qi::parse; char const* f(input); char const* l(f + strlen(f)); bool result1 = parse(f,l,endian_word_type,voxel); bool result2 =((!full_match) || (f ==l)); if ( result1 && result2) { //doing nothing, parsing data is pass to voxel alreay } else { std::cerr << "Error: not match!!" << std::endl; exit(1); } } typedef boost::uint16_t bs_int16; typedef boost::uint32_t bs_int32; int main ( int argc, char *argv[] ) { namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; using qi::big_word; using qi::big_dword; boost::uint32_t ui; float uf; binary_parser("\x01\x02\x03\x04",big_word,ui); assert(ui=0x01020304); binary_parser("\x01\x02\x03\x04",big_word,uf); assert(uf=0x01020304); return 0; }' I almost copy the example, but why this binary parser doesn't work. I use Mac OS 10.5.8 and gcc 4.01 compiler.

    Read the article

  • How does one restrict xml with an XML Schema?

    - by John
    Hello, I want to restrict xml with a schema to a specific set. I read this tutorial http://www.w3schools.com/schema/schema_facets.asp This seems to be what I want. So, I'm using Qt to validate this xml <car>BMW</car> Here is the pertinent source code. QXmlSchema schema; schema.load( QUrl("file:///workspace/QtExamples/ValidateXSD/car.xsd") ); if ( schema.isValid() ) { QXmlSchemaValidator validator( schema ); if ( validator.validate( QUrl("file:///workspace/QtExamples/ValidateXSD/car.xml") ) ) { qDebug() << "instance is valid"; } else { qDebug() << "instance is invalid"; } } else { qDebug() << "schema is invalid"; } I expected the xml to match the schema definition. Unexpectedly, QxmlSchemaValidator complains. Error XSDError in file:///workspace/QtExamples/ValidateXSD/car.xml, at line 1, column 5: Content of element car does not match its type definition: String content is not listed in the enumeration facet.. instance is invalid I suspect this is a braino. How does one restrict xml with an XML Schema? Thanks for your time and consideration. Sincerely, -john Here is the xsd from the tutorial. <xs:element name="car"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Audi"/> <xs:enumeration value="Golf"/> <xs:enumeration value="BMW"/> </xs:restriction> </xs:simpleType> </xs:element>

    Read the article

  • Actually XSLT Lookup (Store variables during loop and use in it another template)

    - by krisvandenbergh
    Is there a way to store a variable/param during a for-each loop in a sort of array, and use it in another template, namely <xsl:template match="Foundation.Core.Classifier.feature">. All the classname values that appear during the for-each should be stored. How would you implement that in XSLT? Here's my current code. <xsl:for-each select="Foundation.Core.Class"> <xsl:for-each select="Foundation.Core.ModelElement.name"> <xsl:param name="classname"> <xsl:value-of select="Foundation.Core.ModelElement.name"/> </xsl:param> </xsl:for-each> <xsl:apply-templates select="Foundation.Core.Classifier.feature" /> </xsl:for-each> Here's the template in which the classname parameters should be used. <xsl:template match="Foundation.Core.Classifier.feature"> <xsl:for-each select="Foundation.Core.Attribute"> <owl:DatatypeProperty rdf:ID="{Foundation.Core.ModelElement.name}"> <rdfs:domain rdf:resource="$classname" /> </owl:DatatypeProperty> </xsl:for-each> </xsl:template> The input file can be found at http://krisvandenbergh.be/uml_pricing.xml

    Read the article

  • C++: parsing with simple regular expression or shoud I use sscanf?

    - by Helltone
    I need to parse a string like func1(arg1, arg2); func2(arg3, arg4);. It's not a very complex parsing problem, so I would prefer to avoid resorting to flex/bison or similar utilities. My first approch was to try to use POSIX C regcomp/regexec or Boost implementation of C++ std::regex. I wrote the following regular expression, which does not work (I'll explain why further on). "^" "[ ;\t\n]*" "(" // (1) identifier "[a-zA-Z_][a-zA-Z0-9_]*" ")" "[ \t\n]*" "(" // (2) non-marking "\[" "(" // (3) non-marking "[ \t]*" "(" // (4..n-1) argument "[a-zA-Z0-9_]+" ")" "[ \t\n]*" "," ")*" "[ \t\n]*" "(" // (n) last argument "[a-zA-Z0-9_]+" ")" "]" ")?" "[ \t\n]*" ";" Note that the group 1 captures the identifier and groups 4..n-1 are intended to capture arguments except the last, which is captured by group n. When I apply this regex to, say func(arg1, arg2, arg3) the result I get is an array {func, arg2, arg3}. This is wrong because arg1 is not in it! The problem is that in the standard regex libraries, submarkings only capture the last match. In other words, if you have for instance the regex "((a*|b*))*" applied on "babb", the results of the inner match will be bb and all previous captures will have been forgotten. Another thing that annoys me here is that in case of error there is no way to know which character was not recognized as these functions provide very little information about the state of the parser when the input is rejected. So I don't know if I'm missing something here... In this case should I use sscanf or similar instead? Note that I prefer to use C/C++ standard libraries (and maybe boost).

    Read the article

  • SpeechRecognizer causes ANR... I need help with Android speech API.

    - by Dondo Chaka
    I'm trying to use Android's speech recognition package to record user speech and translate it to text. Unfortunately, when I attempt initiate listening, I get an ANR error that doesn't point to anything specific. As the SpeechRecognizer API indicates, a RuntimeException is thrown if you attempt to call it from the main thread. This would make me wonder if the processing was just too demanding... but I know that other applications use the Android API for this purpose and it is typically pretty snappy. java.lang.RuntimeException: SpeechRecognizer should be used only from the application's main thread Here is a (trimmed) sample of the code I'm trying to call from my service. Is this the proper approach? Thanks for taking the time to help. This has been a hurdle I haven't been able to get over yet. Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.domain.app"); SpeechRecognizer recognizer = SpeechRecognizer .createSpeechRecognizer(this.getApplicationContext()); RecognitionListener listener = new RecognitionListener() { @Override public void onResults(Bundle results) { ArrayList<String> voiceResults = results .getStringArrayList(RecognizerIntent.EXTRA_RESULTS); if (voiceResults == null) { Log.e(getString(R.string.log_label), "No voice results"); } else { Log.d(getString(R.string.log_label), "Printing matches: "); for (String match : voiceResults) { Log.d(getString(R.string.log_label), match); } } } @Override public void onReadyForSpeech(Bundle params) { Log.d(getString(R.string.log_label), "Ready for speech"); } @Override public void onError(int error) { Log.d(getString(R.string.log_label), "Error listening for speech: " + error); } @Override public void onBeginningOfSpeech() { Log.d(getString(R.string.log_label), "Speech starting"); } }; recognizer.setRecognitionListener(listener); recognizer.startListening(intent);

    Read the article

  • URL protocol handler shell execute problem

    - by Chuck
    Hi, I'm working on a small hobby web site where I'm able to launch a local app with certain arguments based on links. Setting up a protocol wasn't difficult, as described in http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx, but I have one dilemma: Let's say the protocol is: foo:127.0.0.1:1111, so a link like href="foo:127.0.0.1:1111" would launch an app like: bar.exe "%1". Since I don't have any control over bar.exe (if I had, then it would be no problem to just parse it, obviously), I need some help parsing %1. bar.exe will launch correctly if it's run as bar.exe 127.0.0.1:1111, but not if it's run as bar.exe foo:127.0.0.1:1111. So I guess my question is... is there ANY way to tell the registry to pass on not %1, but a trimmed %1? (Thinking in terms of regexp where you have match[0] = all of the matched, match[1] = first capture in the matched text). I can solve it by having a .bat instead of .exe, but as I would like to make it as easy as possible for the user to use, I would LOVE it if I could handle it all stricly in registry. Any help is greatly appreciated! Chuck

    Read the article

< Previous Page | 81 82 83 84 85 86 87 88 89 90 91 92  | Next Page >