bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function bool bValidPalindrome = true; int n = s.size(); int front = 0; int back = n - 1; while (front < back) { while (front < back && !isAlphaNumeric(s[front])) front++; while (front < back && !isAlphaNumeric(s[back])) back--; if (front != back && !charEqual(s[front], s[back])) { bValidPalindrome = false; break; } front++; back--; } return bValidPalindrome; }
bool isPalindrome(string s) { if (s.size() == 0) return true; int iNumber = 'A' - 'a'; int a = 0; int b = s.size() - 1; while (a < b) { while(a < b && !isAlphaNumeric(s[a])) ++a; while(a < b && !isAlphaNumeric(s[b])) --b; char sa = (s[a] >= 'A' && s[a] <= 'Z') ? s[a] - iNumber : s[a]; char sb = (s[b] >= 'A' && s[b] <= 'Z') ? s[b] - iNumber : s[b]; if (sa != sb) return false; ++a; --b; } return true; }
TPS_PUBLIC char *Util::URLEncode (Buffer &data) { int i; BYTE *buf = (BYTE*)data; int len = (int)data.size(); int sum = 0; for (i = 0; i < len; i ++) { if (buf[i] == ' ') { sum+=1; } else if (isAlphaNumeric(buf[i])) { sum+=1; } else { sum+=3; } } char *ret = (char *)PR_Malloc(sum + 1); // allocate more than we may need char *cur = ret; for (i = 0; i < len; i ++) { if (buf[i] == ' ') { *cur++ = '+'; } else if (isAlphaNumeric(buf[i])) { *cur++ = buf[i]; } else { *cur++ = '%'; *cur++ = bin2hex(buf[i] >> 4); *cur++ = bin2hex(buf[i]); } } *cur = '\0'; // null-terminated return ret; }
bool isPalindrome(string s) { if (s.size() == 0) return true; int start = 0; int end = s.size()-1; while (start < end) { if (!isAlphaNumeric(s[start])) { //start != char start++; } else if (!isAlphaNumeric(s[end])) { //end != char end--; } else if (s[start] == s[end] || (s[start]+'a'-'A') == s[end] || s[start] == (s[end]+'a'-'A')) {//match start++; end--; } else { return false; } } return true; }
bool isPalindrome(string s) { if(s.empty()) return true; int len = s.size(); int i = 0, j = len - 1; while(i < j){ while(!isAlphaNumeric(s[i])){ i++; if(i == j) return true; //i与j之间都是非法字符 } while(!isAlphaNumeric(s[j])){ j--; if(i == j) return true; //i与j之间都是非法字符 } if(!isSame(s[i], s[j])) return false; i++; j--; } return true; }
static int isValidGrepStr(char *str) { int i = 0; while (str[i] != '\0') { if ( isAlphaNumeric(str+i) || str[i]=='.' || str[i]=='*' || str[i]=='?' ) i++; else return 0; } return 1; }
void Scanner::identifier() { while (isAlphaNumeric(peek())) { advance(); } auto text = source_.substr(start_, current_- start_); auto it = keywords.find(text); TokenType type = IDENTIFIER; if (it != keywords.end()) type = it->second; addToken(type); }
int getNextWordIndex(char *string, int len, int prevEnd) { if (prevEnd > len || *string == '\0') { return -1; } if (*string == '\0' && prevEnd == 0) { return -1; } int i = 0; while(!(isAlphaNumeric(*(string + i + prevEnd)))) { i++; } return (i + prevEnd); }
inline static bool consumeNamedEntity(SegmentedString& source, StringBuilder& decodedEntity, bool& notEnoughCharacters, UChar additionalAllowedCharacter, UChar& cc) { StringBuilder consumedCharacters; HTMLEntitySearch entitySearch; while (!source.isEmpty()) { cc = source.currentChar(); entitySearch.advance(cc); if (!entitySearch.isEntityPrefix()) break; consumedCharacters.append(cc); source.advanceAndASSERT(cc); } notEnoughCharacters = source.isEmpty(); if (notEnoughCharacters) { // We can't an entity because there might be a longer entity // that we could match if we had more data. unconsumeCharacters(source, consumedCharacters); return false; } if (!entitySearch.mostRecentMatch()) { unconsumeCharacters(source, consumedCharacters); return false; } if (entitySearch.mostRecentMatch()->length != entitySearch.currentLength()) { // We've consumed too many characters. We need to walk the // source back to the point at which we had consumed an // actual entity. unconsumeCharacters(source, consumedCharacters); consumedCharacters.clear(); const int length = entitySearch.mostRecentMatch()->length; const LChar* reference = entitySearch.mostRecentMatch()->entity; for (int i = 0; i < length; ++i) { cc = source.currentChar(); ASSERT_UNUSED(reference, cc == *reference++); consumedCharacters.append(cc); source.advanceAndASSERT(cc); ASSERT(!source.isEmpty()); } cc = source.currentChar(); } if (entitySearch.mostRecentMatch()->lastCharacter() == ';' || !additionalAllowedCharacter || !(isAlphaNumeric(cc) || cc == '=')) { decodedEntity.append(entitySearch.mostRecentMatch()->firstValue); if (entitySearch.mostRecentMatch()->secondValue) decodedEntity.append(entitySearch.mostRecentMatch()->secondValue); return true; } unconsumeCharacters(source, consumedCharacters); return false; }
void snarfAlphanumericString(char c, char *buffer) { char *bufferPtr; bufferPtr = buffer; do { if (bufferPtr < &buffer[MAX_NAME_SIZE]) *bufferPtr++ = c; c = getNextChar(); } while (c!=EOF && isAlphaNumeric(c)); *bufferPtr = '\0'; oopsThatWasTheWrongChar(c); }
bool isAlphaNumeric(const string &input) { bool status = false; unsigned char c; for(int i = 0; i < (int)input.size(); ++i) { status = true; c = input[i]; if(isAlphaNumeric(c) == false) { status = false; break; } } return(status); }
bool QgsAuthConfigIdEdit::validate() { QString authcfg( leAuthCfg->text() ); bool curvalid = (( authcfg == mAuthCfgOrig && authcfg.size() == 7 ) || ( mAllowEmpty && authcfg.size() == 0 ) ); if ( !curvalid && authcfg.size() == 7 && isAlphaNumeric( authcfg ) ) { curvalid = QgsAuthManager::instance()->configIdUnique( authcfg ); } if ( mValid != curvalid ) { mValid = curvalid; emit validityChanged( curvalid ); } return curvalid; }
String Preprocessor::passIdentifier() { if (!isAlpha()) { logError("%s:%u: Expected identifier", files.back().name, files.back().line); throw Exception("Expected identifier"); } String identifier; while (isAlphaNumeric()) { identifier.append(1, c(0)); advance(1); } return identifier; }
// http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm String uri_encode(const char* const uri) { static const char DEC2HEX[16 + 1] = "0123456789ABCDEF"; String result; const char* current = uri; while('\0' != *current) { char ch = *current; if(isAlphaNumeric(ch)) { result += ch; } else { // escape this char result += '%'; result += DEC2HEX[ch >> 4]; result += DEC2HEX[ch & 0x0F]; } ++current; } return result; }
/* Regular expression evaluator * --> size parameters are number of bytes in string excluding null char */ static int mygrep (char *ss, int size_ss, char *line, int size_line) { int sspos = 0; int linepos = 0; int i = 0; while (sspos <= size_ss && i <= size_line && linepos < size_line) { if (sspos == size_ss) return 1; if ( isAlphaNumeric(line+i) == 0 ) { // Non-alphanumeric character linepos++; i = linepos; sspos = 0; continue; } if ( line[i] == '\0' ) { linepos++; i = linepos; sspos = 0; continue; } else if ( ss[sspos] == '.' ) { if ( isAlphaNumeric(line+i) ) { i++; sspos++; } } else if ( isAlphaNumeric(ss+sspos) == 1 ) { if ( (sspos+1 <= size_ss) && ((isAlphaNumeric(ss+sspos+1) == 1) || (ss[sspos+1] == '\0') || (ss[sspos+1] == '.')) ) { if ( ss[sspos] == line[i] ) { // MATCH sspos++ ; i++ ; continue; } else { linepos++; i = linepos; sspos = 0; } } else if ( (sspos+1 < size_ss) && (ss[sspos+1] == '*') ) { while ( ss[sspos] == line[i] ) i++ ; sspos += 2; continue; } else if ( (sspos+1 < size_ss) && (ss[sspos+1] == '?') ) { if ( ss[sspos] == line[i] ) { i++; sspos += 2; continue; } else { sspos += 2; continue; } } else ; } else ; //end while loop } return 0; }
/* isLeadingOrTrailing: determines if the hyphen just found is leading or trailing */ int isLeadingOrTrailing(char s[], int pos) { return pos == 0 || !isAlphaNumeric(s[pos-1]) || !isAlphaNumeric(s[pos+1]); }
nsresult txXSLTNumber::getCounters(Expr* aGroupSize, Expr* aGroupSeparator, Expr* aFormat, txIEvalContext* aContext, txList& aCounters, nsAString& aHead, nsAString& aTail) { aHead.Truncate(); aTail.Truncate(); nsresult rv = NS_OK; nsAutoString groupSeparator; int32_t groupSize = 0; if (aGroupSize && aGroupSeparator) { nsAutoString sizeStr; rv = aGroupSize->evaluateToString(aContext, sizeStr); NS_ENSURE_SUCCESS(rv, rv); double size = txDouble::toDouble(sizeStr); groupSize = (int32_t)size; if ((double)groupSize != size) { groupSize = 0; } rv = aGroupSeparator->evaluateToString(aContext, groupSeparator); NS_ENSURE_SUCCESS(rv, rv); } nsAutoString format; if (aFormat) { rv = aFormat->evaluateToString(aContext, format); NS_ENSURE_SUCCESS(rv, rv); } uint32_t formatLen = format.Length(); uint32_t formatPos = 0; PRUnichar ch = 0; // start with header while (formatPos < formatLen && !isAlphaNumeric(ch = format.CharAt(formatPos))) { aHead.Append(ch); ++formatPos; } // If there are no formatting tokens we need to create a default one. if (formatPos == formatLen) { txFormattedCounter* defaultCounter; rv = txFormattedCounter::getCounterFor(NS_LITERAL_STRING("1"), groupSize, groupSeparator, defaultCounter); NS_ENSURE_SUCCESS(rv, rv); defaultCounter->mSeparator.AssignLiteral("."); rv = aCounters.add(defaultCounter); if (NS_FAILED(rv)) { // XXX ErrorReport: out of memory delete defaultCounter; return rv; } return NS_OK; } while (formatPos < formatLen) { nsAutoString sepToken; // parse separator token if (!aCounters.getLength()) { // Set the first counters separator to default value so that if // there is only one formatting token and we're formatting a // value-list longer then one we use the default separator. This // won't be used when formatting the first value anyway. sepToken.AssignLiteral("."); } else { while (formatPos < formatLen && !isAlphaNumeric(ch = format.CharAt(formatPos))) { sepToken.Append(ch); ++formatPos; } } // if we're at the end of the string then the previous token was the tail if (formatPos == formatLen) { aTail = sepToken; return NS_OK; } // parse formatting token nsAutoString numToken; while (formatPos < formatLen && isAlphaNumeric(ch = format.CharAt(formatPos))) { numToken.Append(ch); ++formatPos; } txFormattedCounter* counter = 0; rv = txFormattedCounter::getCounterFor(numToken, groupSize, groupSeparator, counter); if (NS_FAILED(rv)) { txListIterator iter(&aCounters); while (iter.hasNext()) { delete (txFormattedCounter*)iter.next(); } aCounters.clear(); return rv; } // Add to list of counters counter->mSeparator = sepToken; rv = aCounters.add(counter); if (NS_FAILED(rv)) { // XXX ErrorReport: out of memory txListIterator iter(&aCounters); while (iter.hasNext()) { delete (txFormattedCounter*)iter.next(); } aCounters.clear(); return rv; } } return NS_OK; }
bool consumeHTMLEntity(SegmentedString& source, Vector<UChar, 16>& decodedEntity, bool& notEnoughCharacters, UChar additionalAllowedCharacter) { ASSERT(!additionalAllowedCharacter || additionalAllowedCharacter == '"' || additionalAllowedCharacter == '\'' || additionalAllowedCharacter == '>'); ASSERT(!notEnoughCharacters); ASSERT(decodedEntity.isEmpty()); enum EntityState { Initial, Number, MaybeHexLowerCaseX, MaybeHexUpperCaseX, Hex, Decimal, Named }; EntityState entityState = Initial; UChar32 result = 0; Vector<UChar, 10> consumedCharacters; while (!source.isEmpty()) { UChar cc = *source; switch (entityState) { case Initial: { if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ' || cc == '<' || cc == '&') return false; if (additionalAllowedCharacter && cc == additionalAllowedCharacter) return false; if (cc == '#') { entityState = Number; break; } if ((cc >= 'a' && cc <= 'z') || (cc >= 'A' && cc <= 'Z')) { entityState = Named; continue; } return false; } case Number: { if (cc == 'x') { entityState = MaybeHexLowerCaseX; break; } if (cc == 'X') { entityState = MaybeHexUpperCaseX; break; } if (cc >= '0' && cc <= '9') { entityState = Decimal; continue; } source.push('#'); return false; } case MaybeHexLowerCaseX: { if (isHexDigit(cc)) { entityState = Hex; continue; } source.push('#'); source.push('x'); return false; } case MaybeHexUpperCaseX: { if (isHexDigit(cc)) { entityState = Hex; continue; } source.push('#'); source.push('X'); return false; } case Hex: { if (cc >= '0' && cc <= '9') result = result * 16 + cc - '0'; else if (cc >= 'a' && cc <= 'f') result = result * 16 + 10 + cc - 'a'; else if (cc >= 'A' && cc <= 'F') result = result * 16 + 10 + cc - 'A'; else { if (cc == ';') source.advanceAndASSERT(cc); return convertToUTF16(legalEntityFor(result), decodedEntity); } break; } case Decimal: { if (cc >= '0' && cc <= '9') result = result * 10 + cc - '0'; else { if (cc == ';') source.advanceAndASSERT(cc); return convertToUTF16(legalEntityFor(result), decodedEntity); } break; } case Named: { HTMLEntitySearch entitySearch; while (!source.isEmpty()) { cc = *source; entitySearch.advance(cc); if (!entitySearch.isEntityPrefix()) break; consumedCharacters.append(cc); source.advanceAndASSERT(cc); } notEnoughCharacters = source.isEmpty(); if (notEnoughCharacters) { // We can't an entity because there might be a longer entity // that we could match if we had more data. unconsumeCharacters(source, consumedCharacters); return false; } if (!entitySearch.mostRecentMatch()) { ASSERT(!entitySearch.currentValue()); unconsumeCharacters(source, consumedCharacters); return false; } if (entitySearch.mostRecentMatch()->length != entitySearch.currentLength()) { // We've consumed too many characters. We need to walk the // source back to the point at which we had consumed an // actual entity. unconsumeCharacters(source, consumedCharacters); consumedCharacters.clear(); const int length = entitySearch.mostRecentMatch()->length; const UChar* reference = entitySearch.mostRecentMatch()->entity; for (int i = 0; i < length; ++i) { cc = *source; ASSERT_UNUSED(reference, cc == *reference++); consumedCharacters.append(cc); source.advanceAndASSERT(cc); ASSERT(!source.isEmpty()); } cc = *source; } if (entitySearch.mostRecentMatch()->lastCharacter() == ';' || !additionalAllowedCharacter || !(isAlphaNumeric(cc) || cc == '=')) { return convertToUTF16(entitySearch.mostRecentMatch()->value, decodedEntity); } unconsumeCharacters(source, consumedCharacters); return false; } } consumedCharacters.append(cc); source.advanceAndASSERT(cc); } ASSERT(source.isEmpty()); notEnoughCharacters = true; unconsumeCharacters(source, consumedCharacters); return false; }
void loop( void ) { // Serial.write( '\n' ) ; // send a char // Serial.write( '\r' ) ; // send a char // Serial5.write( '-' ) ; // send a char // adding a constant integer to a string: stringThree = stringOne + 123; Serial.println(stringThree); // prints "stringThree = 123" // adding a constant long interger to a string: stringThree = stringOne + 123456789; Serial.println(stringThree); // prints " You added 123456789" // adding a constant character to a string: stringThree = stringOne + 'A'; Serial.println(stringThree); // prints "You added A" // adding a constant string to a string: stringThree = stringOne + "abc"; Serial.println(stringThree); // prints "You added abc" stringThree = stringOne + stringTwo; Serial.println(stringThree); // prints "You added this string" // adding a variable integer to a string: int sensorValue = analogRead(A0); stringOne = "Sensor value: "; stringThree = stringOne + sensorValue; Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has // adding a variable long integer to a string: long currentTime = millis(); stringOne = "millis() value: "; stringThree = stringOne + millis(); Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has // do nothing while true: while (true); #if 0 // get any incoming bytes: if (Serial.available() > 0) { int thisChar = Serial.read(); //////// int thisChar = 'a'; // say what was sent: Serial.print("You sent me: \'"); Serial.write(thisChar); Serial.print("\' ASCII Value: "); Serial.println(thisChar); // analyze what was sent: if (isAlphaNumeric(thisChar)) { Serial.println("it's alphanumeric"); } if (isAlpha(thisChar)) { Serial.println("it's alphabetic"); } if (isAscii(thisChar)) { Serial.println("it's ASCII"); } if (isWhitespace(thisChar)) { Serial.println("it's whitespace"); } if (isControl(thisChar)) { Serial.println("it's a control character"); } if (isDigit(thisChar)) { Serial.println("it's a numeric digit"); } if (isGraph(thisChar)) { Serial.println("it's a printable character that's not whitespace"); } if (isLowerCase(thisChar)) { Serial.println("it's lower case"); } if (isPrintable(thisChar)) { Serial.println("it's printable"); } if (isPunct(thisChar)) { Serial.println("it's punctuation"); } if (isSpace(thisChar)) { Serial.println("it's a space character"); } if (isUpperCase(thisChar)) { Serial.println("it's upper case"); } if (isHexadecimalDigit(thisChar)) { Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)"); } // add some space and ask for another byte: Serial.println(); Serial.println("Give me another byte:"); Serial.println(); } #endif #if 0 sensorValue = analogRead(A0); // apply the calibration to the sensor reading sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); Serial.print("sensor = " ); Serial.print(sensorValue); // in case the sensor value is outside the range seen during calibration outputValue = constrain(sensorValue, 0, 255); // print the results to the serial monitor: Serial.print("\t output = "); Serial.println(outputValue); // fade the LED using the calibrated value: analogWrite(9/*ledPin*/, sensorValue); delay(1); #endif #if 0 // read the analog in value: sensorValue = analogRead(A0); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(9/*analogOutPin*/, outputValue); // print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); // delay(1000); #endif #if 0 digitalWrite( 0, HIGH ) ; // set the red LED on digitalWrite( 0, LOW ) ; // set the red LED on digitalWrite( 1, HIGH ) ; // set the red LED on digitalWrite( 1, LOW ) ; // set the red LED on digitalWrite( 4, HIGH ) ; // set the red LED on digitalWrite( 4, LOW ) ; // set the red LED on digitalWrite( 5, HIGH ) ; // set the red LED on digitalWrite( 5, LOW ) ; // set the red LED on digitalWrite( 6, HIGH ) ; // set the red LED on digitalWrite( 6, LOW ) ; // set the red LED on digitalWrite( 7, HIGH ) ; // set the red LED on digitalWrite( 7, LOW ) ; // set the red LED on digitalWrite( 8, HIGH ) ; // set the red LED on digitalWrite( 8, LOW ) ; // set the red LED on digitalWrite( 9, HIGH ) ; // set the red LED on digitalWrite( 9, LOW ) ; // set the red LED on digitalWrite( 10, HIGH ) ; // set the red LED on digitalWrite( 10, LOW ) ; // set the red LED on digitalWrite( 11, HIGH ) ; // set the red LED on digitalWrite( 11, LOW ) ; // set the red LED on digitalWrite( 12, HIGH ) ; // set the red LED on digitalWrite( 12, LOW ) ; // set the red LED on digitalWrite( 13, HIGH ) ; // set the red LED on digitalWrite( 13, LOW ) ; // set the red LED on #endif #if 0 // int a = 123; // Serial.print(a, DEC); // for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ ) for ( uint32_t i = 0 ; i <= NUM_ANALOG_INPUTS ; i++ ) { int a = analogRead(i); // int a = 123; Serial.print(a, DEC); Serial.print(" "); // Serial.write( ' ' ) ; // send a char // Serial.write( 0x30 + i ) ; // send a char // Serial.write( 0x30 + ((a/1000)%10) ) ; // send a char // Serial.write( 0x30 + ((a/100)%10) ) ; // send a char // Serial.write( 0x30 + ((a/10)%10) ) ; // send a char // Serial.write( 0x30 + (a%10) ) ; // send a char // Serial.write( ' ' ) ; // send a char } Serial.println(); #endif #if 0 volatile int pin_value=0 ; static volatile uint8_t duty_cycle=0 ; static volatile uint16_t dac_value=0 ; // Test digitalWrite led_step1() ; delay( 500 ) ; // wait for a second led_step2() ; delay( 500 ) ; // wait for a second // Test Serial output Serial5.write( '-' ) ; // send a char Serial5.write( "test1\n" ) ; // send a string Serial5.write( "test2" ) ; // send another string // Test digitalRead: connect pin 2 to either GND or 3.3V. !!!! NOT on 5V pin !!!! pin_value=digitalRead( 2 ) ; Serial5.write( "pin 2 value is " ) ; Serial5.write( (pin_value == LOW)?"LOW\n":"HIGH\n" ) ; duty_cycle+=8 ;//=(uint8_t)(millis() & 0xff) ; analogWrite( 13, duty_cycle ) ; analogWrite( 12, duty_cycle ) ; analogWrite( 11, duty_cycle ) ; analogWrite( 10 ,duty_cycle ) ; analogWrite( 9, duty_cycle ) ; analogWrite( 8, duty_cycle ) ; dac_value += 64; analogWrite(A0, dac_value); Serial5.print("\r\nAnalog pins: "); for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ ) { int a = analogRead(i); Serial5.print(a, DEC); Serial5.print(" "); } Serial5.println(); Serial5.println("External interrupt pins:"); if ( ul_Interrupt_Pin3 == 1 ) { Serial5.println( "Pin 3 triggered (LOW)" ) ; ul_Interrupt_Pin3 = 0 ; } if ( ul_Interrupt_Pin4 == 1 ) { Serial5.println( "Pin 4 triggered (HIGH)" ) ; ul_Interrupt_Pin4 = 0 ; } if ( ul_Interrupt_Pin5 == 1 ) { Serial5.println( "Pin 5 triggered (FALLING)" ) ; ul_Interrupt_Pin5 = 0 ; } if ( ul_Interrupt_Pin6 == 1 ) { Serial5.println( "Pin 6 triggered (RISING)" ) ; ul_Interrupt_Pin6 = 0 ; } if ( ul_Interrupt_Pin7 == 1 ) { Serial5.println( "Pin 7 triggered (CHANGE)" ) ; ul_Interrupt_Pin7 = 0 ; } #endif }
bool A6httplib::Get(String host, String path) { char end_c[2]; end_c[0]=0x1a; end_c[1]='\0'; _path=path; _host=host; String body_content=""; int body_content_start=0; int body_content_start_content=0; int body_content_end=0; dummy_string="GET "+ _path; _A6l->A6conn->write(dummy_string.c_str()); log("GET "+ _path); _A6l->A6conn->write(" HTTP/1.1"); log(" HTTP/1.1"); _A6l->A6conn->write("\r\n"); log("\r\n"); _A6l->A6conn->write("HOST: "); log("HOST: "); _A6l->A6conn->write(_host.c_str()); log(_host); _A6l->A6conn->write("\r\n\r\n"); log("\r\n"); _A6l->A6command(end_c, "OK", "yy", 30000, 1, NULL); //begin send data to remote server _A6l->A6conn->write(end_c); String rcv=""; rcv.reserve(500); String rcv_str="+CIPRCV"; char ch='\0'; int count_incoming_bytes=0; String body_rcvd_data=""; String bytes_in_body=""; int bytes_read=0; while(1) { if( _A6l->A6conn->available() ) { rcv=""; rcv=_A6l->A6conn->readStringUntil('\r'); int index=rcv.indexOf('+'); if(index!=-1) { log(rcv); logln("found +"); int colon_index=rcv.indexOf(':'); String cutfromrecvd = rcv.substring( index,colon_index); //logln(cutfromrecvd); if(cutfromrecvd == rcv_str) logln("recieving data"); else logln("not equal"); int comma_index=rcv.indexOf(','); if(comma_index!=-1) { bytes_in_body = rcv.substring(colon_index+1, comma_index); int no_of_bytes=bytes_in_body.toInt(); logln(no_of_bytes); long now=millis(); long ntime=0; // int bytes_read=0; while(1) { long ntime=millis(); if(ntime-now>10000 || (bytes_read==no_of_bytes) ) { log(ntime); log('\t'); logln(now); log(bytes_read); log('\t'); logln(no_of_bytes); logln(F("timeout occured getting number of bytes")); break; } if(_A6l->A6conn->available()) { body_rcvd_data += (char) _A6l->A6conn->read(); bytes_read+=1; } } logln(bytes_read); break; } else logln("no comma found"); } } } logln(body_rcvd_data); // String body_content=""; // int body_content_start=body_rcvd_data.indexOf("\n\n"); body_content_start=body_rcvd_data.indexOf("\r\n\r\n"); log(F("found double newline at ")); logln(body_content_start); // int body_content_end=0; if(body_content_start!=-1) { for(int i=body_content_start; i<bytes_read; i++) if( isAlphaNumeric(body_rcvd_data[i]) ) body_content_start_content=i; // body_content_end=body_rcvd_data.indexOf("\r\n",body_content_start+5); body_content_end = bytes_read; //body_content=body_rcvd_data.substring(body_content_start_content+1,body_content_end); log(F("body content start at ")); logln(body_content_start_content+1); log(F("body content end at ")); logln(body_content_end); // logln(body_content); // log("check-"); body_content = body_rcvd_data.substring(body_content_start + 4,body_content_end); logln(body_content); } logln(F("now going to close tcp connection")); _A6l->A6command((const char *)"AT+CIPCLOSE", "OK", "yy", 15000, 1, NULL); delay(100); logln("closed"); _A6l->A6command((const char *)"AT+CIPSTATUS", "OK", "yy", 10000, 2, NULL); logln(F("http request done")); }