ll library::parseLong(string s) { //simple use of atoll char *c = toCharArray(s); ll x = atoll(c); return x; }
XObjectPtr FunctionSubstringBefore::execute( XPathExecutionContext& executionContext, XalanNode* /* context */, const XObjectPtr arg1, const XObjectPtr arg2, const LocatorType* /* locator */) const { assert(arg1.null() == false && arg2.null() == false); const XalanDOMString& theFirstString = arg1->str(); const XalanDOMString::size_type theFirstStringLength = length(theFirstString); if (theFirstStringLength == 0) { return createEmptyString(executionContext); } else { const XalanDOMString& theSecondString = arg2->str(); const XalanDOMString::size_type theSecondStringLength = length(theSecondString); if (theSecondStringLength == 0) { return createEmptyString(executionContext); } else { const XalanDOMString::size_type theIndex = indexOf(theFirstString, theSecondString); if (theIndex == theFirstStringLength) { return createEmptyString(executionContext); } else { XPathExecutionContext::GetAndReleaseCachedString theResult(executionContext); XalanDOMString& theString = theResult.get(); theString.assign( toCharArray(theFirstString), theIndex); // Create a string of the appropriate length... return executionContext.getXObjectFactory().createString(theResult); } } } }
bool ProfileBackend::setActiveProfile (QString profileName) { bool success = false; #ifdef HAVE_LIBPROFILE success = profile_set_profile (toCharArray (profileName)) == 0; #endif if (success) m_activeProfile = profileName; return success; }
bool ProfileBackend::setVolumeLevel (QString profileName, int level) { bool success = #ifdef HAVE_LIBPROFILE profile_set_value_as_int (toCharArray (profileName), keyVolume, level) == 0; #else false; #endif if (success) m_profileVolumes[profileName] = level; return success; }
bool ProfileBackend::setVibration (QString profileName, bool vibration) { bool success = #ifdef HAVE_LIBPROFILE profile_set_value_as_bool (toCharArray (profileName), keyVibration, vibration) == 0; #else false; #endif if (success) m_profileVibrations[profileName] = vibration; return success; }
int PF_set(String args){ auto sep = args.indexOf("="); if(sep == -1){ error(-1000); return -1000;} auto k = args.substring(0,sep); auto v = args.substring(sep+1); char *dest = PV_a; switch(k.charAt(0)){ case 'a': dest = PV_a; break; case 'b': dest = PV_b; break; case 'c': dest = PV_c; break; default: return -1; } v.toCharArray(dest, MAX_ARG_LENGTH); return v.length(); }
XObjectPtr FunctionSubstring::execute( XPathExecutionContext& executionContext, XalanNode* /* context */, const XObjectPtr arg1, const XObjectPtr arg2, const XObjectPtr arg3, const LocatorType* /* locator */) const { assert(arg1.null() == false && arg2.null() == false); const XalanDOMString& theSourceString = arg1->str(); const XalanDOMString::size_type theSourceStringLength = length(theSourceString); if (theSourceStringLength == 0) { return createEmptyString(executionContext); } else { // Get the value of the second argument... const double theSecondArgValue = DoubleSupport::round(arg2->num()); // XPath indexes from 1, so this is the first XPath index.... const XalanDOMString::size_type theStartIndex = getStartIndex(theSecondArgValue, theSourceStringLength); if (theStartIndex >= theSourceStringLength) { return createEmptyString(executionContext); } else { const double theTotal = getTotal(theSourceStringLength, theSecondArgValue, arg3); if (DoubleSupport::isNaN(theSecondArgValue) == true || DoubleSupport::isNaN(theTotal) == true || DoubleSupport::isNegativeInfinity(theTotal) == true || theTotal == 0.0 || theTotal < double(theStartIndex)) { return createEmptyString(executionContext); } else { const XalanDOMString::size_type theSubstringLength = getSubstringLength( theSourceStringLength, theStartIndex, theTotal); XPathExecutionContext::GetAndReleaseCachedString theResult(executionContext); XalanDOMString& theString = theResult.get(); assign( theString, toCharArray(theSourceString) + theStartIndex, theSubstringLength); return executionContext.getXObjectFactory().createString(theResult); } } } }
inline const char * str() const { return toCharArray(); }
const XalanDOMString& XalanDOMStringPool::get(const XalanDOMString& theString) { return get(toCharArray(theString), length(theString)); }
//function for refresh display inline void displayRedraw() { char array[8]; unsigned char xlineMode = 0; if(displayPaused == 0){ for (int line=0;line<2;line++) //for booth lines { if (line)// line 2 { displaySetAddressDDRAM(0x40); displayWriteDataArray("Err "); displaySetAddressDDRAM(0x40); xlineMode = (LineMode / 16); } else //line 1 { displaySetAddressDDRAM(0x00); displayWriteDataArray("Err "); displaySetAddressDDRAM(0x00); xlineMode = (LineMode % 16); } switch(xlineMode) { case 0: break; case 1://1 total distance toCharArray(&array,(totalDistance*395)>>20); //distance*0.000377 = dist in kilometers //toCharArray(&array,(totalDistance*0.000377)); displayWriteDataArray(array); displayWriteDataArray(" km"); break; case 2://2 total consumed capacity toCharArray(&array,(totalConsumedCapacity)/1000);//show in Ah displayWriteDataArray(array); displayWriteDataArray(" Ah"); break; case 3://3 distance toCharArray(&array,(distance*386)>>10); //distance*0.377 = dist in meters //toCharArray(&array,(distance*0.377)); displayWriteDataArray(array); displayWriteDataArray(" m"); break; case 4://4 consumed capacity (mAh) toCharArray(&array,consumedCapacity/921600); //consumed capacity/256/3600 = mAh displayWriteDataArray(array); displayWriteDataArray(" mAh"); break; case 5://5 rest capacity (%) if (actualVoltage>=180) displayWriteDataArray("100 %"); else if (actualVoltage>=80) { toCharArray(&array,(actualVoltage-80)); displayWriteDataArray(array); displayWriteDataArray(" %"); } else displayWriteDataArray("! 0 % !"); break; case 6://6 voltage toCharArray(&array,(10 + actualVoltage/25)); //10V + 1/25V 100 = 4V displayWriteDataArray(array); displayWriteDataArray(" V"); break; case 7://7 current toCharArray(&array,actualCurrent/5); displayWriteDataArray(array); displayWriteDataArray(" A"); break; case 8://8 speed toCharArray(&array,actualSpeed/4); displayWriteDataArray(array); displayWriteData('.'); toCharArray(&array,(actualSpeed % 4)*10/4); displayWriteDataArray(array); displayWriteDataArray("km/h"); break; } } } }
XObjectPtr FunctionSubstringAfter::execute( XPathExecutionContext& executionContext, XalanNode* /* context */, const XObjectPtr arg1, const XObjectPtr arg2, const LocatorType* /* locator */) const { assert(arg1.null() == false && arg2.null() == false); const XalanDOMString& theFirstString = arg1->str(); const XalanDOMString::size_type theFirstStringLength = length(theFirstString); if (theFirstStringLength == 0) { return createEmptyString(executionContext); } else { const XalanDOMString& theSecondString = arg2->str(); const XalanDOMString::size_type theSecondStringLength = length(theSecondString); if (theSecondStringLength == 0) { return arg1; } else { const XalanDOMString::size_type theIndex = indexOf(theFirstString, theSecondString); if (theIndex == theFirstStringLength) { return createEmptyString(executionContext); } else { const XalanDOMString::size_type theSecondStringLength = length(theSecondString); // Find the first character, which will be the offset of the index of the // beginning of the second string, plus the length of the second string. const XalanDOMChar* const theFirstCharacter = toCharArray(theFirstString) + theIndex + theSecondStringLength; // The remaining length is just the opposite -- the length of the string, // minus the index, minus the length of the second string. const XalanDOMString::size_type theSubstringLength = theFirstStringLength - theIndex - theSecondStringLength; XPathExecutionContext::GetAndReleaseCachedString theResult(executionContext); XalanDOMString& theString = theResult.get(); assign( theString, theFirstCharacter, theSubstringLength); return executionContext.getXObjectFactory().createString(theResult); } } } }
/* * Class: org_jnetpcap_PcapUtils * Method: getHardwareAddress * Signature: (Ljava/lang/String;)[B */ JNIEXPORT jbyteArray JNICALL Java_org_jnetpcap_PcapUtils_getHardwareAddress (JNIEnv *env, jclass clazz, jstring jdevice) { #ifndef IFNAMSIZ #define IFNAMSIZ 512 #endif jbyteArray jba = NULL; char buf[IFNAMSIZ]; // convert from jstring to char * toCharArray(env, jdevice, buf); #ifdef WIN32 PIP_INTERFACE_INFO info = getIpInterfaceInfo(); if (info == NULL) { throwException(env, IO_EXCEPTION, "unable to retrieve interface info"); return NULL; } for (int i = 0; i < info->NumAdapters; i ++) { PIP_ADAPTER_INDEX_MAP map = &info->Adapter[i]; /* * Name is in wide character format. So convert to plain UTF8. */ int size=WideCharToMultiByte(0, 0, map->Name, -1, NULL, 0, NULL, NULL); char utf8[size + 1]; WideCharToMultiByte(0, 0, map->Name, -1, utf8, size, NULL, NULL); #ifdef DEBUG printf("#%d name=%s buf=%s\n", i, utf8, buf); fflush(stdout); #endif char *p1 = strchr(utf8, '{'); char *p2 = strchr(buf, '{'); if(p1 == NULL || p2 == NULL) { p1 = utf8; p2 = buf; } if (strcmp(p1, p2) == 0) { PMIB_IFROW row = getMibIfRow(map->Index); #ifdef DEBUG printf("FOUND index=%d len=%d\n", map->Index, row->dwPhysAddrLen); fflush(stdout); #endif jba = env->NewByteArray((jsize) row->dwPhysAddrLen); env->SetByteArrayRegion(jba, (jsize) 0, (jsize) row->dwPhysAddrLen, (jbyte *)row->bPhysAddr); free(row); } } free(info); #else u_char mac[6]; // MAC address is 6 bytes #if defined(Linux) || defined(HPUX) || defined(AIX) || defined(DARWIN) || \ defined(FREE_BSD) || defined(NET_BSD) || defined(OPEN_BSD) mac_addr_sys(buf, mac); #else mac_addr_dlpi(buf, mac); #endif jba = env->NewByteArray((jsize) 6); env->SetByteArrayRegion(jba, 0, 6, (jbyte *)mac); #endif return jba; }