bool test_valid() { for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) { nsDependentCString str8(ValidStrings[i].m8); nsDependentString str16(ValidStrings[i].m16); if (!NS_ConvertUTF16toUTF8(str16).Equals(str8)) return false; if (!NS_ConvertUTF8toUTF16(str8).Equals(str16)) return false; nsCString tmp8("string "); AppendUTF16toUTF8(str16, tmp8); if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8)) return false; nsString tmp16(NS_LITERAL_STRING("string ")); AppendUTF8toUTF16(str8, tmp16); if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16)) return false; if (CompareUTF8toUTF16(str8, str16) != 0) return false; } return true; }
PRBool test_valid() { for (unsigned int i = 0; i < NS_ARRAY_LENGTH(ValidStrings); ++i) { nsDependentCString str8(ValidStrings[i].m8); nsDependentString str16(ValidStrings[i].m16); if (!NS_ConvertUTF16toUTF8(str16).Equals(str8)) return PR_FALSE; if (!NS_ConvertUTF8toUTF16(str8).Equals(str16)) return PR_FALSE; nsCString tmp8("string "); AppendUTF16toUTF8(str16, tmp8); if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8)) return PR_FALSE; nsString tmp16(NS_LITERAL_STRING("string ")); AppendUTF8toUTF16(str8, tmp16); if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16)) return PR_FALSE; if (CompareUTF8toUTF16(str8, str16) != 0) return PR_FALSE; } return PR_TRUE; }
// ----------------------------------------------------------------------------- // AppendBufL // ----------------------------------------------------------------------------- // void AppendBufL( TPtr8& aDest, HBufC* aSrc ) { TInt length = aSrc ? aSrc->Length() * 2 : KNullBuffer; APPEND_BUF_INT( aDest, length ); if( length > 0 ) { TPtr8 tmp8( (TUint8*)aSrc->Ptr(), length, length); __ASSERT_DEBUG( (aDest.MaxLength() - aDest.Length()) > tmp8.Length() , User::Panic( KNullDesC, KErrTooBig ) ); aDest.Append( tmp8 ); } }
TEST(UTF, Invalid16) { for (unsigned int i = 0; i < ArrayLength(Invalid16Strings); ++i) { nsDependentString str16(Invalid16Strings[i].m16); nsDependentCString str8(Invalid16Strings[i].m8); EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8)); nsCString tmp8("string "); AppendUTF16toUTF8(str16, tmp8); EXPECT_TRUE(tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8)); EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0); } }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: read_pdb(const std::string &filename) { std::string line, word ; std::string element_string ; std::ifstream infile(filename) ; int count = 0 ; int frame = 0 ; //string s(line, index, number_characters) ; std::vector<float> vector_x; std::vector<float> vector_y; std::vector<float> vector_z; while(getline(infile,line)) { std::istringstream record(line) ; record >> word ; std::string temp1(word,0,5) ; if(temp1 != "ATOM" && temp1 != "HETAT") { std::cout << "excluding: " << word << std::endl ; } else { std::string tmp(line,0,6) ; _atom_record().push_back(tmp) ; std::string tmp2(line,6,5) ; _atom_index().push_back(stoi(tmp2)) ; std::string tmp3(line,12,4) ; _atom_name().push_back(tmp3) ; std::string tmp4(line,16,1) ; _atom_altloc().push_back(tmp4) ; std::string tmp5(line,17,3) ; _atom_resname().push_back(tmp5) ; std::string tmp6(line,21,1) ; _atom_chain().push_back(tmp6) ; std::string tmp7(line,22,4) ; _atom_resid().push_back(stoi(tmp7)) ; std::string tmp8(line,26,1) ; _atom_icode().push_back(tmp8) ; std::string tmp9(line,30,8) ; vector_x.push_back(stof(tmp9)) ; std::string tmp10(line,38,8) ; vector_y.push_back(stof(tmp10)) ; std::string tmp11(line,46,8) ; vector_z.push_back(stof(tmp11)) ; try { std::string tmp12(line,54,6) ; if(util::has_only_spaces(tmp12)) { _atom_occupancy().push_back("0.00") ; } else { _atom_occupancy().push_back(tmp12) ; } } catch(const std::out_of_range& oor) { _atom_occupancy().push_back("0.00") ; std::cerr<<"Occupancy: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp13(line,60,6) ; if(util::has_only_spaces(tmp13)) { _atom_beta().push_back("0.00") ; } else { _atom_beta().push_back(tmp13) ; } } catch(const std::out_of_range& oor) { _atom_beta().push_back("0.00") ; std::cerr<<"Beta: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp14(line,72,4) ; if(util::has_only_spaces(tmp14)) { _atom_segname().push_back("SEGN") ; } else { _atom_segname().push_back(tmp14) ; } } catch(const std::out_of_range& oor) { _atom_segname().push_back("SEGN") ; std::cerr<<"Segname: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp15(line,76,2) ; if(util::has_only_spaces(tmp15)) { std::cout << "Element not found" << std::endl; element_string = element_from_name(tmp3) ; _atom_element().push_back(element_string) ; } else { _atom_element().push_back(tmp15) ; } } catch(const std::out_of_range& oor) { element_string = element_from_name(tmp3) ; _atom_element().push_back(element_string) ; std::cerr<<"Element: Out of range error: "<< oor.what() <<std::endl ; } try { std::string tmp16(line,78,2) ; if(util::has_only_spaces(tmp16)) { _atom_charge().push_back(" ") ; } else { _atom_charge().push_back(tmp16) ; } } catch(const std::out_of_range& oor) { _atom_charge().push_back(" ") ; std::cerr<<"Charge: Out of range error: "<< oor.what() <<std::endl ; } count++ ; } } _natoms() = count ; infile.close() ; int nf = _number_of_frames() ; if(_number_of_frames() == 0) { _x().setZero(_natoms(), 1); _y().setZero(_natoms(), 1); _z().setZero(_natoms(), 1); } else { resize_array() ; } for(int i = 0 ; i < _natoms() ; ++i) { _x()(i,_number_of_frames()) = vector_x[i] ; _y()(i,_number_of_frames()) = vector_y[i] ; _z()(i,_number_of_frames()) = vector_z[i] ; } std::vector<std::string> s_element ; s_element = util::strip_white_space(_atom_element()) ; _atom_selement() = s_element ; dynamic_cast<sasmol::SasMol*>(this)->calc_mass() ; _atom_com() = dynamic_cast<sasmol::SasMol*>(this)->calc_com(frame) ; _number_of_frames() += 1 ; _set_unique_attributes(); /* 1 2 3 4 5 6 7 8 012345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 0 6 1 2 7 ATOM 1 N GLY X 1 -21.525 -67.562 86.759 1.00 0.00 GAG N ATOM 2 HT1 GLY X 1 -22.003 -68.460 86.892 1.00 0.00 GAG H ATOM 3 HT2 GLY X 1 -21.905 -66.929 87.525 1.00 0.00 GAG H */ }
void sasio::Files:: write_pdb(const std::string &filename, int &frame) { std::ofstream outfile(filename) ; std::string time_and_user_string ; time_and_user_string = util::time_and_user(); std::string temp_remark = "REMARK PDB FILE WRITTEN "; temp_remark += time_and_user_string ; std::string remark(temp_remark,0,80) ; std::cout << remark << std::endl ; outfile << remark << std::endl; //std::string dum1 =" 1 2 3 4 5 6 7 8"; //std::string dum2 ="12345678901234567890123456789012345678901234567890123456789012345678901234567890"; //outfile << dum1 << std::endl; //outfile << dum2 << std::endl; std::stringstream line ; std::stringstream my_stringstream; for(int i = 0 ; i < _natoms() ; ++i) { line.str( std::string() ); line.clear() ; std::string tmp(_atom_record()[i],0,6) ; line << std::setfill(' ') << std::setw(6) << tmp ; if(_atom_index()[i] > 99999) { std::string tmp2(std::to_string(99999),0,5) ; line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ; } else if(_atom_index()[i] < -9999) { std::string tmp2(std::to_string(-9999),0,5) ; line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ; } else { std::string tmp2(std::to_string(_atom_index()[i]),0,5) ; line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ; } std::string tmp0 = " "; line << tmp0 ; std::string tmp3(_atom_name()[i],0,4) ; line << std::setfill(' ') << std::setw(4) << std::left << tmp3 ; std::string tmp4(_atom_altloc()[i],0,1) ; line << std::setw(1) << tmp4 ; std::string tmp5(_atom_resname()[i],0,3) ; line << std::setfill(' ') << std::setw(4) << std::left << tmp5 ; std::string tmp6(_atom_chain()[i],0,1) ; line << std::setfill(' ') << std::setw(1) << std::left << tmp6 ; if(_atom_resid()[i] > 9999) { std::string tmp7(std::to_string(9999),0,4) ; line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ; } else if(_atom_resid()[i] < -999) { std::string tmp7(std::to_string(-999),0,4) ; line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ; } else { std::string tmp7(std::to_string(_atom_resid()[i]),0,4) ; line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ; } std::string tmp8(_atom_icode()[i],0,1) ; line << std::setw(4) << std::left << tmp8 ; //std::string f_str = std::to_string(f); //here // my_stringstream << _x()(i,frame) ; //my_stringstream << std::to_string(_x()(i,frame)) ; //line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ; line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ; my_stringstream << _y()(i,frame) ; line << my_stringstream.str() ; my_stringstream << _z()(i,frame) ; line << my_stringstream.str() ; std::string tmp12(_atom_occupancy()[i],0,6) ; line << std::setfill(' ') << std::setw(6) << std::right << tmp12 ; std::string tmp13(_atom_beta()[i],0,6) ; line << std::setfill(' ') << std::setw(6) << std::right << tmp13 ; std::string tmp14(_atom_segname()[i],0,4) ; line << std::setfill(' ') << std::setw(10) << std::right << tmp14 ; std::string tmp15(_atom_element()[i],0,2) ; line << std::setfill(' ') << std::setw(2) << std::right << tmp15 ; std::string tmp16(_atom_charge()[i],0,2) ; line << std::setfill(' ') << std::setw(2) << std::right << tmp16 ; outfile << line.str() << std::endl ; } outfile << "END" << std::endl; outfile.close() ; }